0 votes

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.


in Engine by (37 points)

1 Answer

+1 vote
Best answer

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.

by (840 points)
selected by

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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.