Strange Collision detection

Hi Guys,

Having trouble with the collision in Gdevelop

Edit: Managed to fix this issue. For the benefit of anyone who may be facing this prob in the future:

I tried to have the code like this initially

On player wall collide - stop player
if player.X is < wall.X - player.x = wall.x -50
add a force -20 to X axis
if player.X is > wall.X - player.x = wall.x +50
add a force +20 to X axis

That for some reason, that gave the above problem. Solved it by putting the 2 sets of conditions to their own sets:

On player wall collide
if player.X is < wall.X - stop player
- player.x = wall.x -50
- add a force -20 to X axis

On player wall collide
if player.X is > wall.X - stop player
- player.x = wall.x +50
- add a force +20 to X axis


Ok, but now i’m trying to do a similar thing with player - enemy collision and only one side works again.

Attached is the actual code. Player wall code in the image works but doesn’t work with player - enemy collision

Please help. Thanks

Did you try the action to separate objects?:

Conditions: If player collides with wall/enemy Actions: Stop object player Separate player from wall/enemy (only player will move)
Other than that, I don’t know why your code would work for walls but not for enemies :neutral_face:

You don’t say on which side the collision doesn’t work.

To use points don’t you need to use the expression enemy1.PointX(Centre) instead of enemy1.X(Centre) for example?

Could it simply be that it should be “Center”, not “Centre”? I think I’ve been caught out by that before. Not quite as infuriating as when you’ve typed “Yes” instead of “yes” though!

Hi guys,

Thank you so much, you guys are a real life saver :slight_smile:

Lizard-13:

Thanks! totally overlooked this action. It’s working fine now with that!

MattLB:
Player on left side of screen approaching enemy on the right will cause player to phase through

ddabrahim:
Seems to work when i just use wall.X() instead of wall.PointX()
In fact, i didn’t even know there was such a thing as .PointX XD

MattLB:
Just double checked but Centre instead of Center is correct.
Thanks for the heads up. Didn’t know it was case sensitive

Working fine now with the separate objects as suggested by Lizard-13 :slight_smile: Thank you all!