Why can't my character stand on rigid body?

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

I’m making a 2D platformer. My character is a kinematic body 2d and I have a crate which is a rigid body because I want it to have physics. But when I stand on the crate, my character goes through the crate and the crate kind of rotates wildly and pushes out of the way instead of my character standing on it. I can give more information if needed.

How does the kinematic body know when it’s landed? It sounds like the kinematic body is forcing its way past the rigidbody with complete disregard for it.

Magso | 2019-06-17 15:21

if i make the rigid body mode static then i can stand on it, but you’re right that there is no resistance when i push it in rigid body mode. Their collision masks cover each other’s layers.

lincolnpepper | 2019-06-17 15:46

If your game really needs to use this type of physics, consider using a RigidBody character. The movement usually feels a bit different from Kinematic but it will allow your character to fully interact with other RigidBody nodes

andersmmg | 2019-06-17 18:18

That’s super annoying since i already set up a big class system with a bunch of layers that other things inherit from aswell, but i guess it’s better to do it that way since rigid body has a kinematic mode anyway.

lincolnpepper | 2019-06-17 21:23

I’ve found that the Character mode works best for interacting with other RigidBody nodes, but try different things and find what works best for you.

andersmmg | 2019-06-17 21:25

:bust_in_silhouette: Reply From: Brinux

So I’m a little late to this party, but I had this exact situation come up. I want my Kinematic character to push a crate around, but also be able to stand on it. So here’s my solution in case anyone else trips over this post in the future:

Since your character is a Kinematic body and gravity only happens if you apply a downward force, then don’t do that.

Put another way, apply a downward velocity move_and_slide (vector3(0,-9.8,0)) ONLY when your character is in the air.

Since is_on_floor won’t work in this situation (because your rigid body crate is not a floor), you instead determine this using a downward RayCast coming out of your kinematic character.

If the RayCast’s is_colliding== false, then there’s nothing below your character, so turn on the downward force via move_and_slide, otherwise, reset the downward force on your character to zero.

This means technically that your kinematic character is floating over the crate, but it looks like it’s standing on it. Then when you move off the crate, the RayCast’s is_colliding==false, your script clicks on your downward (gravitational) force until the character hits the ground.

Hope that helps.

:bust_in_silhouette: Reply From: Bhgt

You try setting infinite_inertia parameter in the move_and_slide() function?
Something like,

velocity = move_and_slide(velocity, Vector2.UP, false, 4, PI/4, false)