Movement question

When I use WSAD movement, say, at 100 force, it moves at that speed when one button is pressed.

But when I press, for example, W and D at the same time (so the player is moving diagonally in a northeast direction), they move slightly faster. I guess because there are two forces moving on them at the same time.

Anyone know a good work around for this?

Thanks!

Hello, JohnnyMangoes

I can’t reproduce. Isn’t that just your impression? Look at my test where the black object is the only one that moves diagonally, but it’s not faster than the other objects:

Events

Preview
Gif

Maybe it’s an optical illusion? I’ll test it again. Thanks for making that btw, very thoughtful of you.

The one on the diagonal IS moving faster. Its the pythagorean theorem, and the diagonal distance is always longer than the horizontal or vertical in a right angled triangle. The distance is calculated as black_square_distance ^2 = green_square_distance ^ 2 + red_square_distance ^2

So if red and green squares move 100 pixels across/down each, then black square has moved 141 pixels in the same time. To travel more pixels in the same time means it has to be going faster.

2 Likes

That was very interesting. I didn’t think about that. I created the same test but added a sprite that had the force applied with an angle of 45 degrees.

ScreenRecorderProject17

2 Likes

Yeah I knew I wasn’t imagining things, looks like objects that have a force placed onto them on from two axes at once have about a 40% speed increase. I wonder how to work around that, or just leave it in. Not sure if I should have it doing math just on basic character movement, it’s not super intrusive but it possibly could just be an exploit for character movement.

Also thanks for taking the time to put that together.

Wow, nice! Thanks for the correction, MrMen!!! :brain:

@JohnnyMangoes, sorry for the mistake!

If you have some “good” topdown games, it would be interesting if you could test it out to see how they handle it. I don’t think you should necessarily do the same as other games, but if they are famous topdown it could serve as a guideline. But feel free to opt for what you think is best for your game.

1 Like

I compared the top-down behavior and it calculates the diagonals at the same speed in all directions. You could use the top-down behavior with the remap top-down behavior to assign it to the WASD keys or you could simulate the keypresses.

I used a chat bot that kept giving the wrong math but it eventually pointed me in the right direction.
This converts distance to an angle and then calculates the force using cos() and sin() times the force of 100. The key presses don’t add speed, they add distance. The atan2() converts the distance to an angle.

Thanks. Seems hella complicated to just get it to move consistently. I’m about to playtest some other games on Steam to see if this problem pops up at all in other scenarios.

The other option which might be preferred by some. It would require using logic for every situation or at minimum events for left and down & left and up etc…

If right and down apply force by direction.

Apply force by direction is consistent. You could use that instead. And again, the other behaviors work properly.

You can look at the top down Javascript code. It’s even more complex.

I figure it out, just assigned a MoveX and MoveY value and multiplied them by .59 when the players is holding down two keys. Seems to replicate consistent movement (for now).

Seems to be an issue with all engines not just this one. can’t believe I didn’t think of that (lack of sleep)

1 Like