I want to be able to move an object to the position of the player in a smooth fashion. Lerp would be good in this form:
var start : Transform; var end : Transform; function Update () { transform.position = Vector3.Lerp(start.position, end.position, Time.time);
but the object always arrives at its destination in the same amount of time no matter the distance. I need the object to be moving on average at a constant velocity.
This form would be better:
var target : Transform; var smooth = 5.0; function Update () { transform.position = Vector3.Lerp ( transform.position, target.position, Time.deltaTime * smooth);
..giving it a realistic speed up slow down touch. However in this form it slows down the closer it gets to its target. I would like it to be slower at it leaves its position and speed up a bit to a constant velocity on its approach to its target
basically I would like to know how to make my object speed up to constant velocity and then slow down. How can do i do that? how to I make an object speed up?
Thanks a ton!
i know i'm slowpoke, but can you explain how to use it?
– anon49448616Put that script on an object, then drag in objects from the hierarchy that represent the start and end positions for the lerp.
– Eric5h5@Eric5h5 +1 and 4K :) I checked your website..!! Pretty cool things!
– anon4553185Is there a way to accomplish this without using yield? I have a script with a 'destination' as Vector3 (sometimes updated from another script) and a max-speed variable as float, this technique proved difficult to implement onto that. Would it be ideal to add it as a separate component?
– thojoh370You can't have a coroutine without using yield. You can use [MoveObject][1] for more flexibility. [1]: http://wiki.unity3d.com/index.php?title=MoveObject
– Eric5h5