Unity学习笔记-移动物体的各种方式总结

1. Translate

Translate (plusX, plusY, plusZ)
直接通过在当前的x,y,z上加plusX, plusY, plusZ来移动物体
如果希望使移动不受帧率影响
Translate (plusX * Time.deltatime, plusY * Time.deltatime, plusZ * Time.deltatime)

2. MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);

MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);
Moves a point current in a straight line towards a target point.

3. Lerp

Vector3.Lerp (Vector3 a, Vector3 b, float t);

https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

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).
按百分比移动,可用于实现物体的速度渐减/渐增移动

4. 给rigidbody一个速度

rb.velocity =

你可能感兴趣的:(Unity学习笔记-移动物体的各种方式总结)