0 votes

My use case is giving movement commands in a Homeworld-esque 3D RTS.

I want my selected unit to rotate to face the location of the movement command in 3D space and then go to that location.

transform = transform.looking_at(targetLocation, Vector3(0,1,0)) will instantly snap the objects rotation to the correct place, which isn't exactly what I want.

I'm looking at trying it with a tween, but since interpolate_property() takes time as an argument that means it would take the same amount of time for the object to rotate 45 degrees as it would to rotate 180 degrees.

Is there a good way to control the rotation speed with tween? Or even a lerp or slerp? I tried a really hacky lerp call (because I didn't know about Quat slerp) already and it's exhibiting some bizarre behaviour and still has the same "takes the same amount of time regardless of how far it rotates" problem.

Is dividing the dot product by the rotation speed and using that as the time argument a possibility (I think this would work in 2D, but I'm missing something in 3D because it may have to rotate on all of its axes. The "Pointing at Target" bit in the Vector Math tutorial seems lacking in detail)?

in Engine by (29 points)

What do you mean by "controlling speed"? Do you mean you just want your tween to have a non-linear speed? You could use easing curves for that.

What do you mean by "controlling speed"? Do you mean you just want your tween to have a non-linear speed? You could use easing curves for that.

No, I mean I want it to turn at no more than 90 degrees/sec (or 120, or 15, or whatever) when it could be turning anywhere from 1 to 180 degrees.

1 Answer

+1 vote
Best answer

So I was overcomplicating it and the answer is "yes" Code below does it:

var rotSpeed = 90 #rotation speed in degrees per second
var angleDiff = acos(transform.basis.z.dot(

var timeToTurn = angleDiff/deg2rad(rotSpeed)

by (29 points)
selected by
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.