- Home /
Question by
dltmdrl1244 · May 31 at 12:09 AM ·
rotationlerplookatslerp
How to make a gameobject look at(rotate) another gameobject smoothly?
Hi there, I have a trouble with rotating a gameobject.
I want to make my gameobject A looks at gameobject B when I click mouse button, but not in one frame, I want to rotate it smoothly as if person rotate its body.
So I came up with a function 'slerp'. but I can't do well with it. Can you give me a solution?
Here is my code :
public GameObject target;
void Update()
{
FollowTarget();
}
void FollowTarget()
{
Quaternion lookOnLook = Quaternion.LookRotation(target.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, lookOnLook, Time.deltaTime * speed);
}
and I put another gameobject B in object A's component variable, which I want A to look at, but I failed.
Comment
Your answer
Follow this Question
Related Questions
Get slerp to work just as LookAt(,Vector3.right) does 1 Answer
Transition current camera rotation to 0,0,0 1 Answer
Rotate object towards mouse position 1 Answer
MoveTowards rotation not always functioning 0 Answers
Slowly Rotate to Look at 1 Answer