+3 votes

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.

in Engine by (243 points)

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.

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.

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

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.

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.

2 Answers

+2 votes

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 moveandslide, 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.

by (328 points)
+1 vote

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)
by (16 points)
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.