Jumping into pixel-perfect holes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Elkondo

I’m trying to make a simple retro platformer as my first project and I want my character to be able to jump into pixel-perfect holes. I found some hints here, made the hitbox smaller with larger collision margins, it helped a little bit as he can now move inside the holes just fine.

Problem is, at 60 physics fps the character fails to find the hole at higher speeds and considers it a wall. Upping the fps works, but also breaks is_on_wall() which now always returns ‘false’ unless I lower the collision margins.
I tried different combinations of physics fps, hitbox size and margins and couldn’t find one that consistently would both allow for entering the hole at high enough speed and wouldn’t break is_on_wall() or, in some cases, is_on_ceiling() and is_on_floor().

I’m very new to Godot, so any hints on how to achieve consistent behavior like this would be appreciated.

:bust_in_silhouette: Reply From: Footurist

I suspect continuous collision would help alot. What kind of PhysicsBody2D do you use for your character? If any case, a RayCast2D would probably be a good solution, too. You can read about it in the docs and watch some tutorials about it. It’s a ray, that casts at a set length in a set direction from your body and will be able to detect collisions way better than RigidBody2D or KinematicBody2D.

I’m using KinematicBody2D. Adding RayCast2D solved my issue.
Simply put, I placed a RayCast2D pointing at my character’s feet right in front of him. In the script I check if is_colliding() has changed value and if it has and player is still trying to move, I change the global_position of my character so that his feet are at the same height as the collision is/was.
I did some other safety checks, but in short that’s how I got it to work. It still wouldn’t work if the character was fast enough to miss the hole completely, but it’s good enough for my needs.

Elkondo | 2018-02-28 01:19

Great! Yeah, pixel perfect physics can be very anooying to achieve.But in general, if you tried both RayCast2D and turning on continuous collision detection on your physics body, then upping the Physics FPS is the only other option I am aware of. So if you want extremely fast movement, you probably have to take the performance hit until you get there.

Footurist | 2018-02-28 01:34