0 votes

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.

in Engine by (116 points)

Have you looked into the look_at() function?

1 Answer

0 votes

its called look_at()

by (617 points)

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

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…

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 Frequently asked questions and 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 [email protected] with your username.