lerp between two xyz rotation values

Hi there

Apologies for the noobiness of this question,

I want to create a lerp ( or even better a smoothstep) between two rotation values. My code below creates a very sudden transition over one frame. Duration is a float with val 20f

many thanks in advance!

	void Update () {
		
		if (armstate == 1) { 
		
			transform.eulerAngles = Vector3.Lerp (startRot,endRot,duration);
			
			armstate = 0;
		}
		
		
		if (armstate == 2) { 
		
			transform.eulerAngles = Vector3.Lerp (endRot,startRot,duration);
			armstate = 0;
		}

The final parameter of the Lerp() is a value between 0 and 1 inclusive. A standard way of using Lerp() is to create a timer and use the timer in the final parameter calculation. Here is your code with some changes. It probably doesn’t do want you want, but it does show Lerp() in action. Attach this script to a Cube object and hit play.

using UnityEngine;
using System.Collections;
 
public class LerpDemo : MonoBehaviour {
	
	Vector3 startRot = new Vector3(-30.0f,-30.0f,-30.0f);
	Vector3 endRot   = new Vector3(60.0f, 60.0f, 60.0f);
	
	int armstate = 0;
	float duration = 20.0f;
	float timer = 0.0f;
	
	void Update () {
		
		timer += Time.deltaTime;
		if (timer > duration) {
			armstate = (armstate + 1) % 2;
			timer = 0.0f;
		}
 
       if (armstate == 0) { 
           transform.eulerAngles = Vector3.Lerp (startRot,endRot,timer/duration);
       }
 
       if (armstate == 1) { 
         transform.eulerAngles = Vector3.Lerp (endRot,startRot,timer/duration);
       }
	}
}

to lerp from grot to a target angle named vRot::

gRot = new Vector3(Mathf.LerpAngle(gRot.x,vRot.x,pFrame),Mathf.LerpAngle(gRot.y,vRot.y,pFrame),Mathf.LerpAngle(gRot.z,vRot.z,pFrame));

works for me :slight_smile: