Ask here your questions to get help using GDevelop.
By Chris_P_Cream
#65520 I am fairly new to GDevelop and I've been able to figure things out on my own, until now.

I am making a Frogger style game and this is what I'm trying to achieve:

When a direction key is pressed, move the player exactly 100 pixels in that direction. But I want the player to actually move and not simply jump/teleport 100 pixels away.

I've tried several different methods but nothing seems to work. I tried using a force to move the player and then stopping the forces after the player has traveled 100 pixels. That almost works but the player always goes a little too far.

The map is designed on a grid of 100x100 pixel blocks. That's why the movement needs to be exactly 100 pixels every time.

This type of movement seems like it should be easy to achieve but I haven't had any luck...
User avatar
By Lizard-13
#65521 Like a classic RPG?, I would do it this way:
(5.37 KiB) Downloaded 105 times

It's very condensed, the importat thing is to calculate a destination when you press a key (for example if you press the Right key, the destination will be current X position + 100), move until you reach the destination, then stop the player and set the position = destination, this way the player will be always inside the grid, without exceeding it.
By Chris_P_Cream
#65545 I was actually using a similar method but mine wasn't nearly as complex (or versatile) as that example. My biggest mistake was using forces for movement because I was using a timer to limit how fast a key could be pressed. Using the "moving" variable as a switch to control the movement, is a much better solution.

Thank you!
By delonious
#69436 AMAZING! Thanks so much!

But how do you deal with collisions?

I would normally use "separate two objects" but the player freezes when it comes into contact with a collision.
User avatar
By erdo-dp
#69439
delonious wrote:AMAZING! Thanks so much!

But how do you deal with collisions?

I would normally use "separate two objects" but the player freezes when it comes into contact with a collision.


You have to move every object based on grid positions (check in wich virtual cell the object will be placed based in the direction you're trying to move it... you can manage it from memory with a variable structure) and based on those values set your own collision system to prevent colliding objects to be placed in the same virtual cell. That's RPG grid-based movement and collision.

Or set a condition to cancel the movement towards a direction when the object hits a collision. I mean, cancel all the conditions that performs the movement, not just block it, because otherwise the object will freeze in a collision.