how to move_and_slide a rigidbody?

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

I have a box and it is rigidbody.
I want the box can rotate when it near a wall.
However, rigidbody do not have move_and_slide functionality so it will not rotate when the box near a wall.

So how can I solve the problem?
Is there any move_and_slide for rigidbody?

Thank you

What do you mean by “rotate when near a wall”?

kidscancode | 2018-06-15 15:38

I mean when the box adjacent to a box static body it cannot rotate

icqqq | 2018-06-15 15:59

:bust_in_silhouette: Reply From: kidscancode

Rigid bodies are not controlled like kinematics. move_and_slide is there to give your kinematic body a collision response. However, rigid bodies, because they are controlled by the physics engine, automatically respond to collisions by rotating, bouncing, etc.

When using rigid bodies, you don’t control the body directly. You apply forces (add_force()) or impulses (apply_impulse()) to the body and the physics engine moves it appropriately. However, you must be careful to use these correctly.

See Using RigidBody2D for an introduction on working with RigidBody2D.

If you need a more specific answer, you’ll have to share more details of your implementation.

For example, I have two box adjacent together.
One is static body, and another one is a rigidbody.

I apply torque to the rigidbody and hope it can rotate.
However, since it is adjacent to the static body, the rotation seems blocked by the static body and hence the rigidbody does not rotate.

So my question is if I can work around it to make it rotate like the move_and_slide in kinematic body?

Thanks

icqqq | 2018-06-16 04:08

is it impossible?

icqqq | 2018-06-18 08:03