Page 1 of 1

Move a fixed distance

PostPosted: Mon 12 Mar 2018, 00:10
by Chris_P_Cream
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...

Re: Move a fixed distance

PostPosted: Mon 12 Mar 2018, 01:25
by Lizard-13
Like a classic RPG?, I would do it this way:
(5.37 KiB) Downloaded 56 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.

Re: Move a fixed distance

PostPosted: Tue 13 Mar 2018, 01:05
by Chris_P_Cream
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!