Check direction of collision using Platypus

I’m using Platypus to make a platformer, and my player character uses platypus.move() for horizontal movement since I’m controlling my own horizontal velocity with acceleration and friction.

The problem is, when I collide with a wall, I need to handle this velocity myself by setting it to 0.

I can do this with the WALL_CONTACT message, but this only works on the first frame, so my velocity keeps going up after that initial collision. In my case I’m actually clipping through the wall because my chosen movement speed is too fast (if there’s actually a Box2D style “bullet” behaviour for dealing with this in Platypus that’s another workaround).

I can also do this with has_wall_contact() which runs every frame, but because my character is colliding with the wall every frame, the character can no longer move away from the wall.

My idea is to check the direction of the collision, because then I can write code for both left and right inputs to handle this, for example if I’m moving into a wall’s left side, I can check to see if I’m still moving right to stop the player from moving, but allow the player to move left.

Is there a way to handle this with Platypus? Or is there another workaround that I might have missed?

Why does your velocity increase if you set it to 0 on wall contact?

Because I’m still holding the input down, so acceleration continues to be applied.

To stop accelerating when touching a wall, I need to check for wall collision using has_wall_collision(), and I end up with the same problem. I can’t accelerate in either direction if I’m touching a wall.

Why not stop applying acceleration, at least in the direction of the wall?

That’s what I’m trying to figure out. :sweat_smile: Does Platypus have any mechanism for checking which direction you’re colliding from?

I solved it. I decided to use two extra raycasts, one for each side of the player, and used that to check collision direction.

If I wanted to spend more time on this, I’d try to expose the raycast results that happen within Platypus and use that to save a couple raycast calls, but for this project my workaround works fine.

Nice!!!

Yep, Platypus should expose this, or at least include the direction in the wall contact message. You can add a feature request to Platypus if you’d like to see this implemented.

1 Like