How would I stop a RigidBody2D from moving after a player stops touching it?

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

I have a RigidBody2D that moves when a KinematicBody2D hits it. I want the rigid boy to only move when the kinematic body pushes it.

Is there any way where if the two aren’t touching each other, the rigid body stops moving?

:bust_in_silhouette: Reply From: DaddyMonster

Yup, RigidBody2D has sleeping which is what you need. Just set RigidBody2D.sleeping to true and it’ll automatically flip to false when there’s a collision and run the physics engine. Then just set is to true again when there’s no collision.

Is there any code I would have to implement too? I set the RigidBody2D’s sleeping to true, but now it doesn’t move when I touch it.

15erixman | 2021-10-22 18:02

Try enabling “Contact Monitor” and setting “Contacts Reported” to a value greater than 0. Make sure can sleep is true.

DaddyMonster | 2021-10-22 18:56

I still can’t get it to work. I have collision shapes on both the rigidbody2d and the kinematicbody2d. Would I need to add something else to those?

15erixman | 2021-10-26 00:46