Hi, I’m having a bit of trouble getting a turret to rotate towards the player. I need it to have a max rotate speed and clamped rotation range so I thought
Vector3.RotateTowards looked like a sure winner. But I’m getting some very “frantic rotation” unexpected results out of it.
Thanks,
Todd
You’ll probably get some more helpful replies if you post your current code for review.
I’ve been through so many versions that haven’t worked I didn’t really have one that stood out as ‘closer to success’ than the others. But here’s where it sits now:
var rotateTurret : Vector3 = Vector3.RotateTowards(transform.position, ObjectToTrack.transform.position, .1, 180);
transform.localRotation.x = rotateTurret.x;
I really only need/want it to rotate on one axis. My attempt here is that it would be limited to 180 degrees of rotation and rotate pretty slowly (the .1).
Thanks,
Todd
Or, maybe posting code won’t help. 
Hey,
I think your angles are messed up. Check the docs to see the return values of each function and the expected params.
If I’m not mistake you cant use the values the way you used them.
Thanks. I’ve been reading through a lot of the documentation and I guess, I have to admit, the problem is I’m having trouble understanding some of it. For example, the description for RotateTowards reads as:
“Rotates a vector current towards target.”
And it’s defined as:
static function RotateTowards (current : Vector3, target : Vector3, maxRadiansDelta : float, maxMagnitudeDelta : float) : Vector3
The way I read that the first argument is the position of object A, the second argument is the position of object B, the third is a measure in radians of the rotation range of the object and the final argument is the maximum amount it can rotate at a time.
But I’m not clear on whether the fourth argument is measured in radians or degrees and even worse, I’m really at a loss as to exactly what the returning Vector3 will be a vector to. Is it in degrees in world space, or degrees from the current rotation. And that’s the piece that’s not falling into place…of course…the most important one.
And I can’t find a decent working example anywhere (there wasn’t one in the documentation).
So, that’s where I stand.
Todd
what about using Vector3.Angle to determine the angle yourself and then using Mathf.MoveTowardsAngle to move it?
I’ll read up on those and let you know.
Thanks,
Todd