简体   繁体   中英

Set lerp to over time. in MS

I am very confused on how exactly I use vector3.Lerp()

I am trying to move an object from Point A to Point B over time.

Vector3 goal = Vector3.Lerp(object.position, player.Position, 5000);
NAPI.Entity.SetEntityPosition(object.handle, goal);

I am not sure what the last param in Lerp represents, if it is "time" or if it is "distance". No matter what I put there, it always instantly teleports the game object from A to B. I am NOT using UnityEngine this is a MOD for a game. so using things like time.DeltaTime or transform are not available for me.

The goal is to try and figure out how to move from A to B over a set time. For instance Move the object from A to B over a 5 seconds timespan, not instantly.

I am not sure what the last param in Lerp represents

Whenever you're in that situation, the documentation is almost always the first place to look. In this case, we get this information:

When t = 0 returns a. When t = 1 returns b. When t = 0.5 returns the point midway between a and b.

Remember this doesn't just run once. You can't just call the method and let it handle the entire animation for you. You have to redraw the scene numerous times, where you calculated the new position each time. At each new draw, think about how much time ( t ) has passed since the animation started vs how much time you want the entire animation to take ( T ), and use the ratio t/T as your argument.

DeltaTime通常用在最后一个数字中...基本上是您要移动每个呼叫的数量(一路一直),因此... 0.016将使它每秒花费约1秒,每秒更新60次

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM