Having trouble with the collision in Gdevelop
I’m just trying to make the player stop when i hit the wall. Works on one side but on the other, collision detection does not activate and my player just walks through it.
Not using platform behaviours as the behaviours seem to clash with some of the things i have in mind
Any help will be much appreciated. Thanks
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
January 26, 2018, 12:52pm
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?
January 26, 2018, 11:38pm
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!
Thank you so much, you guys are a real life saver
Thanks! totally overlooked this action. It’s working fine now with that!
Player on left side of screen approaching enemy on the right will cause player to phase through
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
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
Thank you all!