#move_and_collide() vs move_and_slide

3 messages · Page 1 of 1 (latest)

tardy reef
#

Hello,
So i coded a simple 2d side-scrolling platformer using move_and_slide() for character movement. Pretty straightforward. But I saw that move_and_collide() returns the object collided with (so I can check eg: is it a door? if so, press enter to open, etc) so i wanted to use that for all my movement.

But now with move_and_collide() the player gets stuck on the floor, and it returns every frame the floor object, which is meaningless to me... What do I do about that? If I use layer masks to ignore the floor, of course the player falls... so I want to collide with the floor to stay on it, but not collide EVERY FRAME so I can't move. Or am I doing this all the totally wrong way? Lol thanks for the help!

thorn lily
#

I would revert back to move_and_slide()

For something like a door, I would attach an Area2D or something to your door object and detect whether or not the player overlaps a door area.. If so, you may enter, etc.