I'm using Vector3.Lerp()
to instantiate some prefabs at a set distance from each other. This works, but I've just started playing with Vector3.Slerp
.
This creates a nice arc, however I'd like the arc to happen on either the X or Z axis, not the Y. So rather than arcing up into the air, the prefabs remain in contact with the ground at all times.
I've been reading up on euler local transforms
however I'm not entirely sure if that's the right thing.
If anyone could offer some advice, or input, I'd greatly appreciate it.
I did a little tinkering (and can't claim to fully understand the reasoning as of now, or whether this is the only solution) but it seems as long as the y-component of the start and end input Slerp Vectors are zero, the object will only travel in the xz plane. Below is an example:
Vector3 startpos;
Vector3 endpos;
Vector3 yoffset;
float t;
void Start()
{
startpos = new Vector3(-5, 2, 0);
endpos = new Vector3(3, 2, 2);
yoffset = new Vector3(0, 2, 0);
}
void Update()
{
t = (t+Time.deltaTime);
transform.position = Vector3.Slerp(startpos - yoffset, endpos - yoffset, t/5f);
transform.position += yoffset;
}