- Home /
Move object position on specific axis with Lerp
I was wondering if there was any way to lerp an objects x position using a number of some sort. So starting from the objects current position, lerp object position x to value 10 on the x-axis.
The pseudo code looks like this:
float curPosX = -1.136f; this.transform.position.x = Lerp(transform.position.x, curPosX, Time.deltaTime);
Essentially I'm trying to lerp the x position of the object to a number value corresponding on the grid.
Is this possible in javascript or c# on unity? I'm fairly new to programming in unity, and I was wondering if I could do this with the engine?
I think this might work: transform.position = Vector3.Lerp(new Vector3(0,0,0),new Vector3(0,0,10),Time.time/5);
I'm gonna test it tomorrow.
Your actual pseudo code looks fine to me as well. Just change Lerp with $$anonymous$$athf.Lerp and it should work.