Unity 移動 和 旋轉 [小結]
移動:
Position:
直接修改位置資料
關鍵詞 |
函式 |
說明 |
|
Position |
|
Translate |
Transform.Translate(Vector3 dir) |
【勻速】朝著一個方向,一直移動。 (dir * speed 可以控制速度) 適合鍵盤控制物體上下左右運動 |
MoveTowards |
Vector3.MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta); |
【勻速】朝著目標移動。(當前位置,目標位置,最大速度) |
Lerp |
Vector3 Lerp(Vector3 a, Vector3 b, float t); |
【線性插值】朝著目標移動。(當前位置,目標位置,速度) |
Slerp |
Vector3 Slerp(Vector3 a, Vector3 b, float t); |
【球形插值】朝著目標移動。(當前位置,目標位置,速度) |
SmoothDamp |
Vector3 v = Vector3.zero; Vector3.SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime) |
平滑的從A逐漸移動到B點。適用於相機的跟隨 (當前位置,目標位置,xx,耗時) |
AddForce |
Rigidbody.AddForce(Vector3.right * Force, ForceMode.Force); |
對該物體施加某個方向的力 |
MovePosition |
Rigidbody.MovePosition(Vector3 target) |
剛體在物理效果的作用下,向著目標移動 |
velocity |
Rigidbody.velocity = new Vector3(1, 0, 0); |
剛體的速度(X軸方向的速度為1) |
|
其餘的動畫運動,ITween,關節運動 不在這裡講解 |
|