#RigidBody2D platformer player controller -- stuck on walls

1 messages · Page 1 of 1 (latest)

forest crow
#

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:

  1. 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.)

  2. 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!

void linden
#

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

Have you tried this? Character to Rigid Body Interaction

forest crow
#

Even in that demo though it seems pretty buggy. Boxes can still phase through walls/floor and if you do add player collision you can get launched off of stuff

forest crow
#

The other issue I have is that Godot Physics bugs out in my game for some reason when I create rigidbodies--they start flying off to the left for no reason when they touch the ground

When I use rapier physics it works fine

#

Currently looking through this example to see how it works
https://godotengine.org/asset-library/asset/2725
Looks like they set friction to 0 on the player and that definitely helps with the wall-sticking. However that allows for more sliding on slopes than I would like

forest crow
#

Following up on this -- I've decided to go with 0 friction for now.
I'll keep playing with both character controllers to see which works better for my game

vestal sequoia
#

I think as soon as you need a rigidbody to react to your players weight like in your lever example you pretty much have to commit to a rigidbody controller