0 votes

Hi, I want a RigidBody2D to rotate towards the player using set_applied_torque() in _integrate_forces(), but I can’t find the right formula to achieve that. My understanding is I have to find the direction (an angle in radians, I guess?) towards the player’s position and then rotate in one or the other direction until the RigidBody’s rotation matches.

If I’m correct, finding out that angle works via (player.global_position - global_position).angle() – but what do I compare it to to find out what torque to apply?

Godot version 3.3.1
in Engine by (12 points)

Okay, I came upon a solution to work with for now. Not perfect but does what it should.

var angle_to_player = rad2deg(get_angle_to(player.position))
if angle_to_player >= -90 and angle_to_player <= 0:
    set_applied_torque(get_parent().turning_speed)
else:
    set_applied_torque(-get_parent().turning_speed)

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.