The code structure you want:
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, lerpFactor);
A more adjusted version for your script:
Change the line
transform.Rotate (new Vector3 (a, b, c) * Time.deltaTime);
with
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(a, b, c), Time.deltaTime);
Also,
void Update()
{
if(Input.GetMouseButtonUp(0))
{
//this is only called when button gets relased.
}
if (Input.GetMouseButton (0))
{
//this is called constantly if button is holding down.
}
}
Edit:
This code piece should do what you want:
Quaternion targetRot = Quaternion.identity; //try not to modify this directly, or do it, it's up to you.
bool doRotate = false;
float lerpLimit = 10; //the degrees you want lerp to stop at. set higher than 0 (i suggest higher than 1)
public void SetRotationTarget(Vector3 eulerAngles) //call this method to update the rotation target.
{
targetRot = Quaternion.Euler (eulerAngles); //building a quaternion from given vector3
doRotate = true;
}
void Update()
{
if (doRotate)
{
if (Quaternion.Angle(transform.rotation, targetRot) > lerpLimit) //if angle between our rotation and target rotation is not below limit
{
transform.rotation = Quaternion.Slerp (transform.rotation, targetRot, Time.deltaTime); //Slerp to target rotation
}
else
{
transform.rotation = targetRot;
doRotate = false;
}
}
if(Input.GetMouseButtonUp(0)) //when mouse button 0 is relased
{
SetRotationTarget(new Vector3(a, b, c)); //set new rotation target with values of (a, b, c)
}
}
jumpAndFollow
method. Then you can simply use this:transform.LookAt(transform.position + velocityVector.normalized);
This will make your gameObject's +z axis to line on the vector you give in paranthesis. \$\endgroup\$