I know this is old but I read it so I figure someone else might.
transform.position = Vector3.Lerp works for me.
I notice in your script transform.position = Vector3.Lerp(transform,transform etc
where the ‘from’ and ‘to’ are both the same place, so no movement (so I assume you are snapping in objects in editor?)
Anyway, your issue:
Lerp and Slerp can be treated like weighting in that its third field (where t usually goes) is between 0 and 1 only. As your duration is 1 and startTime is only called once in start() function it seems that t becomes greater than 1 in 1 second and hence your lerp will always Snap To the target (which is its starting position in your case?).
You need to normalise your t factor so that over a chosen duration of time your varibles scale up to 1.
For this I like to use my own timers:
lerpTimer += Time.deltaTime; as for me its easier to get my head around. Then when the lerp is complete, reset your timer; lerpTimer = 0;
I had troubles and I read that I was using lerp incorrectly to begin. It does NOT perform a full smooth movement when called but RETURNS the SCALED DIFFERENCE between two factors every update/fixedupdate with which you are responsible for maintaining and changing the t factor to manipulate the transition yourself. Imagine t as a slider and you are responsible for moving the slider in your code, or as it is, providing a change between 0 and 1, and this decides the speed and smoothness of your transition.
extract of my game :
transform.position = Vector3.Slerp(cannonMoveFrom, cannonMoveTo, lerpTimer/spawnLerp);
lerpTimer += Time.fixedDeltaTime;
here, spawnLerp is fixed value, say 10. So, when lerpTimer hits 10 seconds t = 1; in 5 seconds, 5/10 = 0.5 so lerp is halfway along and transform.position is instantaneously set to halfway between cannonMoveFrom and cannonMoveTo.
I was stumped for a while as I was calling lerp from within a timed if() function and of course the lerp calcaulation was only being performed once every 3 seconds, or whatever.
I needed the lerp to happen seconds after an event so I used the if() to reset the timers and used the else() for the actual Lerp. Worked like a charm.
Hope this helps at least 1 person, with which I will be happy.
Please format your script correctly. And fix it, I'm pretty sure this does not compile: transform.position = Vector3.Lerp(transform, transform, (Time.time - startTime) / duration); Because transform is a Transform object not a Vector3.
– KryptosCan someone rate this post down plz
– p.hufnagl