void executeMovement() {
if (done) return;
prev = new Vector3(transform.position.x, transform.position.y, transform.position.z);
for (float i = 0.0000f; i < 1.0f; i += Time.deltaTime / 10) {
transform.position = Vector3.Lerp(prev, MovingTo, i);
Debug.Log("I: " + i + "| Time.deltaTime: " + Time.deltaTime);
Debug.Break();
}
return;
}
Is the code. On Debug.Break…
I: 0| Time.deltaTime: 0.02
to:
I: 0.6339989| Time.deltaTime: 0.02
up to:
I: 0.9999942| Time.deltaTime: 0.02
BEFORE, the Debug.Break(), that means that if user gets to see his/her first frame, object will be already at it’s location. Is there a way to let it execute that, but per each frame, instead of before first frame?
From what you’ve written, and looking at the code, I would imagine you’re trying to move an object to a target. However, the way you’re going about this issue is completely wrong.
There are a bunch of ways to make something move to a target location. The above is just one example.
Basically, the script will run until the transform reaches the target. The margin value is at least how the close the transform has to be to the target before it stops moving. Speed is how quickly the transform will move toward it’s target. You will need to create variables for both. You could set margin to something like 0.1f and speed to 3f and then tweak the values to get your desired results.
I hope that helps and I would highly recommend that you look through the Unity API because there is a method/function for basically any problem that you may have.
That’s not how Lerp is supposed to be used. Start position has to be the same, otherwise you’d need some more math to have a linear interpolation. The only parameter that has to be changed over time is the third one, but not the way you’ve done it
Sorry if you took offense. Just trying to be helpful. The problem is, that looking at your sample code, there are so many questions to answer, that it’s a better idea to watch one or two of the Unity tutorials which explain movement and all the steps leading to final code than to try and spell it out in text form here in the forum.