- Home /
Rotation Lerp
Hi, I'm making an object rotate around it's axis by using LookAt at an object that is on your mouse position when clicked. All in all this works pretty solid, except I want it to gradually go to the that rotation instead of instantly be there.
Now I even managed that through Quaternion.Lerp, what the real problem is that I want it only to rotate around it's X axis. The code I'm using right now is this:
var rotation = Quaternion.LookRotation(Target.position);
ThisTransform.rotation = Quaternion.Lerp(ThisTransform.rotation, rotation, Time.deltaTime * speed);
Answer by fafase · Nov 28, 2012 at 10:32 AM
Simply set the rotations you don't want to alter back to 0:
void Update(){
var newRotation = Quaternion.LookRotation(Camera.main.transform.position - transform.position).eulerAngles;
newRotation.x = 0;
newRotation.z = 0;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(newRotation), Time.deltaTime);
}
This will only rotate the y-axis
Answer by GeorgeRigato · Nov 21, 2012 at 01:21 PM
try something like this:
var rotation = Quaternion.LookRotation(new Vector3(Target.position.x, ThisTransform.position.y, Target.position.z));
I use C# so maybe the "new" is misplaced.
I've tried it with every possibility within the Vector3, but none giving the effect I want.
Are you calculating the difference between the current pos and target pos to then use look rotation? See this link. http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.LookRotation.html
It Lerps just fine, but I want it to just Lerp over the 1 axis.