Hello, dear community!
I’m trying to make a cube seem floating on a surface, I’ve found a script here:
http://answers.unity3d.com/questions/822484/a.html
public Vector3 from = new Vector3(0f, 0f, 135f);
public Vector3 to = new Vector3(0f, 0f, 225f);
public float speed = 1.0f;
void Update() {
float t = Mathf.PingPong(Time.time * speed * 2.0f, 1.0f);
transform.eulerAngles = Vector3.Lerp (from, to, t);
}
It works great! But it only “lerps” between 2 vectors. Is it possible to lerp between 4 or 5 different cube rotations? The help is appreciated!
EDIT:
I’ve tried writing the following script, but it doesn’t work: “Cannot implicitly convert float to int” in the “transform.eulerAngles = Vector3.Lerp (fromarrays[randomnumber1from], toarrays[randomnumber2to], t);”
using UnityEngine;
using System.Collections;
public class rotation12 : MonoBehaviour {
public Vector3 from = new Vector3(0f, 0f, 135f);
public Vector3 to = new Vector3(0f, 0f, 225f);
public Vector3 from2 = new Vector3(0f, 0f, -100f);
public Vector3 to2 = new Vector3(0f, 0f, 100f);
public Vector3 from3 = new Vector3(0f, 0f, -200f);
public Vector3 to3 = new Vector3(0f, 0f, 200f);
public Vector3 from4 = new Vector3(0f, 0f, -300f);
public Vector3 to4 = new Vector3(0f, 0f, 300f);
public Vector3[] fromarrays;
public Vector3[] toarrays;
public float randomnumber1from;
public float randomnumber2to;
public float speed = 1.0f;
void Start(){
fromarrays[0]=from;
fromarrays[1]=from2;
fromarrays[2]=from3;
fromarrays[3]=from4;
toarrays [0] = to;
toarrays [1] = to2;
toarrays [2] = to3;
toarrays [3] = to4;
}
void Update() {
rotatefuncrion ();
}
void rotatefuncrion(){
float t = (Mathf.Sin (Time.time * speed * Mathf.PI * 2.0f) + 1.0f) / 2.0f;
randomnumber1from = Random.Range (0, 3);
randomnumber2to = Random.Range (0, 3);
transform.eulerAngles = Vector3.Lerp (fromarrays[randomnumber1from], toarrays[randomnumber2to], t);
}
}
Could use suggest what is the reason?