Trouble with "move away" and collisions

I’m just simply trying to do a “fling” of a sprite in a given direction. The object should keep moving until it hits another object and stop.

I tried with forces, checking for collision, stopping all forces and moving object away from obstacle - this makes the moving object stuck.
I then tried changing this to automatic coordinate increase using a directional variable to troubleshoot if it was something with the force amount or something like that - but same result.
I tried changing the coordinate increase to 1 pixel per move to make sure it wasn’t something weird with that - same result.

I then tried to check for collision state and reached the conclusion that even after “move away” the object still is reported as being in collision with the object.

Adding a “trigger once” makes it work on the same axis (up/down movement), but as soon as I move sideways after hitting a bottom/top collision, the side obstacles no longer stop it - as the original collision was never released.

I tried a generic “Object is in collision with object2” condition and the same with “Repeat for each instance of object2”, but the result is the same.

Screenshot shows result AFTER move away.
The text is constantly updating the collision status between the green guy (sprite) and the wall (tiled sprite).

Can you screen shot your events? It isn’t clear form your post whether you are using physics or GDevelop to apply forces, or if it’s something with the events.

I’ve tried both. This is what I currently have.

Using a generic “Player is in collision with walls” instead of the “for each instance of walls” didn’t change anything.

Using forces (apply permanent force on key press in appropriate direction and stop all forces on collision) had the exact same problem.

I’m trying to do this without using physics behaviour. Move away is supposed to separate the objects into a position where they no longer are colliding and that’s not happening…

I don’t think the check for overall speed is doing anything. Remove those conditions from the 4 events.

You want to add an event before the second event (the one checking “Right” key is pressed). In this new event, add the condition “The variable Moving of Player = 0”. Make the 4 key press events as subevent of this new event.


Also, don’t use a repeat for each wall and then check for collision. It runs the possibility of becoming a performance hog.

Instead, just use the “Player is in collision with wall” condition. It filters the walls to the one colliding with player, and will move the player away from it in the actions.

Blockquote
You want to add an event before the second event (the one checking “Right” key is pressed). In this new event, add the condition “The variable Moving of Player = 0”. Make the 4 key press events as subevent of this new event.

That was a leftover from using forces, I did forget to replace with a check for the moving variable.

Blockquote
Instead, just use the “Player is in collision with wall” condition. It filters the walls to the one colliding with player, and will move the player away from it in the actions.

Like I said, I tried that already, same issue happens.

This still produces the same issue with the collision. Even after “move away” the player is still colliding with the wall.

Switching the collision check to before the key press events seems to correct the constant collision, but the player then only moves alongside walls as long as the key remains pressed.

recording

I found a “hacky” way to make this work, by simply moving 1px in the opposite direction of movement after the “move away” action to ensure the player is indeed not colliding.

Does it make a difference if, in the collision action, you select yes to ignore objects touching on their edges?

1 Like

Wow, sometimes I think I should get new glasses, never even saw that toggle. Yep, that pretty much solved it.

1 Like