- Home /
Rotating Toward an Object at a Constant Speed
I am trying to make an object rotate toward another object's position at a constant speed. Kind of like LookAt, except LookAt always looks directly at the object at infinite speed. In mine, the object can only rotate at a certain speed. Can you give me a script in js? Thanks.
Answer by efge · Mar 12, 2011 at 03:52 PM
You could use Mathf.SmoothDamp or Mathf.Lerp.
Or take a look at this answer: smooth LookAt()
Answer by tool55 · Mar 12, 2011 at 05:29 PM
This will turn toward a target position at a constant speed, which is determined by the "damping" variable.
function Update() {
// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
Not a constant speed, it goes real fast if its facing the other way and gets slower the closer the angle is.
Your answer
Follow this Question
Related Questions
LookAt Problem 1 Answer
hoe to rotate a AI as a animation 1 Answer
Arm Look At script Issues (javascript) 1 Answer
How does Transform.Rotate actually work? 1 Answer
How can I make an object always look at the mouse? 2 Answers