Having trouble with colisions on a movement that I am trying

So here is the little mechanic:

  • Player clicks–> makes the sprite rotate to the direction of click
  • sprite constantly moves in the direction which it is facing

On colision make sprite stop.

The problem is this- sometimes when it colides and the sprite stops, I cant get it to start moving again! It just gets stick on a wall.

heres the logic

I am attaching the example file too. Not sure if its graphics will be visible. I wish gdevelop could optionally pack all the graphics within the game logic file.
clickMovement.gdg (15.2 KB)

Problem here is you’re ordering the player sprite to stop when collides with a wall sprite, so the player sprite stops when that happen but it remains in contact with the wall sprite, so it will be stuck there, forever.

There is an event to automatcally separate two sprite objects, you can use it when the game detects some collision, so the player sprite can collide, stop and separate from the wall sprite to be ready for the next movement. Besides I made some changes to your approach and it goes like this:

Yep, sorry… mi GD está en español :smiley:
But you can check the project files here:

clickMovement.zip (7.82 KB)

BTW, when upload your project include all the resource files, not only the project file (*.gdg).

Good luck.

ah this did it! Thanks a bunch.
:smiley:

The name of the action confused me. “separate” is a strange term to use. Maybe call it “bounce” or something like that.

Cool! Glad it helps!

Yes well, to be honest I don’t have idea how that action is called in the english version, but in spanish it makes sense.

Hi again,
would it be possible to limit the rotation of the player object to 4 directions- like it is in pacman?

I always wondered how to do that in gdevelop :smiley:

Easy,

In every click of the cursor make the following calcs and store the result and some data in some variables (let’s call them x_difference, y_difference, axis and direction):

x_difference = Player.X() - MouseX(“”,0)
y_difference = Player.Y() - MouseY(“”,0)
axis = 0
direction = 0

If y_difference is bigger value than x_diferrence then change axis to 1.
if axis is equal to 0 and x_diferrence is a bigger value than 0 or if axis is equal to 1 and y_diferrence is a bigger value than 0 then change direction to 1.

if axis = 0 and direction = 0 then set the player direction angle to 0°
if axis = 1 and direction = 1 then set the player direction angle to 90°
if axis = 0 and direction = 1 then set the player direction angle to 180°
if axis = 1 and direction = 0 then set the player direction angle to 270°

Hope it helps.

Hi, can you post an example file of a simple way to limit the movement to 4 directions :slight_smile:

Thanks in advance. I think it will be good to have it at the forum too - since others have struggled with it.