How can I lock X axis in a RigidBody2D?

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

I’m using RigidBody2D (Character mode) for a massive stone door that falls. Currently, if the player pushes it, it moves like it doesn’t weight anything. The weight and mass properties in the inspector, doesn’t help.

Sample

:bust_in_silhouette: Reply From: kidscancode

Is your player a KinematicBody2D? If so this is because it has infinite_inertia enabled by default. See https://docs.godotengine.org/en/latest/classes/class_kinematicbody2d.html#class-kinematicbody2d-method-move-and-slide for details.

If you disable this, you won’t be able to push the rigid body without applying a force to it.

Thanks! that did the trick. Is there any cons of using it this way? Should I use a StaticBody2D and code the gravity instead? I believe the only thing I using from the physics engine is the gravity.

chantunRey | 2019-06-28 21:26

No, static bodies should not be moved at all.

There are always pros/cons between using rigid vs. kinematic. With kinematic, you’d need to apply gravity yourself, but you have more control over its movement.

kidscancode | 2019-06-28 23:28