Hi
I want to move a object from one place to another place using Lerp:
this.transform.position = Vector3.Lerp(PositionBefore, Griddy.list1[countForPath].transform.position, Time.time);
I want the lerp finished in 2 seconds. How can I do it?
Hi
I want to move a object from one place to another place using Lerp:
this.transform.position = Vector3.Lerp(PositionBefore, Griddy.list1[countForPath].transform.position, Time.time);
I want the lerp finished in 2 seconds. How can I do it?
Time.time makes no sense at all.
The last parameter will be your % of movement. 0 is start, 0.5 is half way and 1 is the end.
So you’ll need a ‘pos’ var. For example:
this.transform.position = Vector3.Lerp(PositionBefore, Griddy.list1[countForPath].transform.position, pos);
pos += speed * Time.deltaTime; //move from 0 to 1.
pos is a variable that will represent how far along you are between the two numbers passed to lerp. We will call them a and b.
speed is whatever speed you’d like to move at. It’s multiplied by the delta so it runs the same rate on different hardware.
Doing it this way for your needs, is clean and simple. You can then just check if pos>=1 to change the coordinates of a and b, to the next place to go in the list, and subtract 1 from pos. We subtract 1 from pos because the speed you’re going at will have pos being 1.1 or something sometimes, and this will lead to jerks if you were just to set pos to 0 again.
–Eric
Hi Thanks
I may didn’t quite get it. Is it in Update()? What if I want to move from point A to Point B within 2seconds? do I need to know the distance between them?
Use the code I linked to.
–Eric
Thank you!