Rotating one RigidBody2D towards another?

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

Does anyone know how I would make a RigidBody2D rotate towards another? I’ve tried:
if groundsense.is_colliding(): var ground = groundsense.get_collider() var groundp = ground.get_global_position() var grangle = groundp.angle on_ground = true if grangle > 3.14: applied_torque -= torque elif grangle < 3.14: applied_torque += torque elif grangle == 3.14:

, where groundsense is a raycast aimed under the players feet. The issue is, I keep getting seemingly random values based on what I am colliding with. Is it the raycast that’s messing things up? If so, how do I fix this? If I messed up in other places, please help me.

Have you looked into the look_at() function?

Ertain | 2020-01-30 03:43

:bust_in_silhouette: Reply From: Merlin1846

its called look_at()

look_at(exampleNodesVector2or3Position)

Does that work with rigid bodies? I want the actual thing to rotate, not just the sprite

a human | 2020-02-05 18:05

It doesn’t work with RigidBody2D.

There’s a different series of actions your code needs to do to make the body face what you want it to point at. I still haven’t figured it out.

The result of my best effort ended up with a bit of… twitchiness. I broke the code afterwards, losing the ability for the RigidBody2D to stop turning… now spins endlessly…

System_Error | 2020-04-07 18:41