Hello -- I am trying to write a platformer player controller using RigidBody2D.
(Yes I am aware there is already CharacterBody2D for this. I had some issues with interactions between CharacterBody2D and RigidBody2D. More on that below*)
I've attach my code for the player controller. It works pretty well but there are a couple issues I'd like to solve:
-
CharacterBody2D can jump up while pressing into a wall. (for example, wall on right side and pressing right, moving character into collision with wall--pressing jump still causes the player to jump) RigidBody2D gets stuck with the wall collision and doesn't jump. I'm not sure how to handle this. (You can see in the attached example, the RigidBody2D character has to jump first, then move the right to clear the wall.)
-
RigidBody2D sticks to walls (again, holding direction into a wall while falling makes player stick to the wall and stop falling. CharacterBody2D will not stick to walls while falling.) Maybe related to (1).
If I can solve these two issues I think the player controller will be good enough for what I am trying to do. I can attach an example project/scene if anyone want to tinker around with it.
*The reason I am not using CharacterBody2D is because I'd like the player to interact with physics objects in the world. I tried using CharacterBody2D at first but I had lots of issues doing simple things like pushing boxes. Or if I want to stand on a RigidBody2D object like a lever arm and have the player's weight cause the lever to rotate. I would have to code all the physics interactions in since the player is not moved by the physics engine. I was able to kind of get around this using collision layers / masks but the behavior is not exactly ideal.
Thanks!