Unity 之 Vector3 .Lerp

定义

public static Vector3 Lerp(Vector3 a, Vector3 b, float t);

a为起始位置,b未终止位置,t为a到b之间的插值()

返回值为a + (b - a) * t

描述

Linearly interpolates between two vectors.

Interpolates between the vectors a and b by the interpolant t. The parameter t is clamped to the range [0, 1]. This is most commonly used to find a point some fraction of the way along a line between two endpoints (e.g. to move an object gradually between those points).

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

注意

为防止在Update()方法中调用Vector3.Lerp(),游戏对象在从a向b移动的过程中越走越慢,最后无限接近b,可令

t = 1 / Vector3.Distance(a , b) * Time.deltaTime

 

若涉及速度和时间

a--->b ,开始时间startTime,当前时间Time.time,速度始终为speed,则

t = (Time.time - startTime) * speed / Vector3.Distance(a,b)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值