iLMS知識社群歷程檔登入
位置: 黃國哲 > Unity
1091228 進階移動Forward
by 黃國哲 2020-12-28 10:57:22, 回應(0), 人氣(567)

使用Forward時,角色會往自己的正前方移動,
所以使用虛擬搖桿的話,搖桿只需要控制自己的轉向
this.transform.Translate (Vector3.forward);


//
this.transform.Translate (Vector3.forward);
this.transform.position += transform.forward;
this.transform.position += Vector3.forward;// Vector3.forward(它代表Vector3(0,0,1))
//

在button上設定下面語法

public void rightbtn ()
    {controller1.transform.Translate(Vector3.forward * 1, Space.Self);}



transform.Translate(Vector3.forward * Time.deltaTime, Space.Self);
要節省定義delta時間可以直接給一個常數如123456等等
transform.Translate(Vector3.forward * 1, Space.Self);


forward       Shorthand for writing Vector3(0, 0, 1).
back       Shorthand for writing Vector3(0, 0, -1).
right       Shorthand for writing Vector3(1, 0, 0).
left              Shorthand for writing Vector3(-1, 0, 0).
up             Shorthand for writing Vector3(0, 1, 0).
down       Shorthand for writing Vector3(0, -1, 0).

one             Shorthand for writing Vector3(1, 1, 1).
zero       Shorthand for writing Vector3(0, 0, 0).


negativeInfinity
Shorthand for writing Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity).

positiveInfinity
Shorthand for writing Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity).




Shorthand for writing Vector3(0, 0, 1).

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void Example()
    {
        transform.position += Vector3.forward * Time.deltaTime;
    }
}



回應