YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

move_and_collide doesn't move along sloped walls when moving at speeds of 1 or lower #8146

Open KormexGit opened 1 day ago

KormexGit commented 1 day ago

Description

move_and_collide can be used to add easy slope movement to something like a top down game. However, the slope movement seems to not work at speeds of about 1.3 or lower. This is a problem for low resolution pixel games that often have low movement values.

With a spd of 1, the player controlled object stops at the slope:

https://github.com/user-attachments/assets/f0babd94-420a-48af-bdb3-355a015a6503

With a spd of 2, the player controlled object moves along the slope:

https://github.com/user-attachments/assets/5ba51c40-382a-4b00-85bf-ed2f1fe57e10

This can also lead to some delay and choppiness if you have acceleration based movement. If I change the code below to this

if hMove != 0 or vMove != 0 {
    spd += 0.01;
}
else {
    spd = 0;
}

Then this is the results:

https://github.com/user-attachments/assets/5b692e5e-2c26-488c-bbe6-de8bfa63bd04

Steps To Reproduce

//create
var hMove = keyboard_check(ord("D")) - keyboard_check(ord("A"));
var vMove = keyboard_check(ord("S")) - keyboard_check(ord("W"));

if hMove != 0 or vMove != 0 {
    spd = 1;
}
else {
    spd = 0;
}

var moveDir = point_direction(0, 0, hMove, vMove);

move_and_collide(lengthdir_x(spd, moveDir), lengthdir_y(spd, moveDir), oWall);

Changing spd to 2 will make the object go along slopes just fine.

Which version of GameMaker are you reporting this issue for?

IDE v2024.1100.0.654 Runtime v2024.1100.0.680

Which operating system(s) are you seeing the problem on?

Windows 10.0.22631.0

Which platform(s) are you seeing the problem on?

Windows

c7ef9cca-b33e-472a-a103-dbd8f8979c80

KormexGit commented 1 day ago

I accidentally uploaded a project with incorrect movement code that always moves right when not holding a key, it still shows the issue but here's a version with fixed code https://api.gamemaker.io/api/github/downloads/facf2edd-c725-44fe-bcde-5c37db4ce3af

attic-stuff commented 19 hours ago

i do not believe this is a bug. move_and_collide moves the agent by a percent of the total movement each iteration, which by default is 4. so if you move like this: move_and_collide(0.8, 0, wall) then the agent will attempt to move (0.8, 0) / 4 pixels, 4 times, which isn't enough to move in and out of colliding with the slope. if you want to move it along the slope at low speeds you need to take advantage offset arguments.