玩家必須按下按鈕,角色向前移動一步,但在跳躍中做到了。
using System.Collections.Generic;
using UnityEngine;
public class playerrr : MonoBehaviour
{
public void MoveUp()
{
transform.Translate(0f, 0f, 1f);
}
public void MoveLeft()
{
transform.Translate(-1f, 0f, 0f);
}
public void MoveRight()
{
transform.Translate(1f, 0f, 0f);
}
}
并且左右移動不是90度,而是40度左右。
uj5u.com熱心網友回復:
1.-“但是是在跳躍中做到的”。
您可以查看Transform.Translate 檔案。轉換發生在執行指令的“突然”時刻,這意味著“立即”應用移動。如果您希望它是漸進的,檔案本身中有一個示例可以做到這一點:
public class ExampleClass : MonoBehaviour
{
void Update()
{
// Move the object forward along its z axis 1 unit/second.
transform.Translate(Vector3.forward * Time.deltaTime);
// Move the object upward in world space 1 unit/second.
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}
}
2.-“不是 90 度,而是大約 40 度。”
然后你需要計算那個方向并移動到那里。請注意,您可以在引數中選擇“Space.Self”來定義平移,同時考慮到感興趣的游戲物件的本地軸系統(通常與此對齊),然后選擇一個滿足您對翻譯。
我會嘗試:
向右 45o:Vector3(1, 0, 1)
向左 45o:Vector3(-1, 0, 1)
向右Vector3(Mathf.sin(Mathf.Deg2Rad(40)), 0, Mathf.cos(Mathf.Deg2Rad(40)))
40o:向左 40o:Vector3(-Mathf.sin(Mathf.Deg2Rad(40)), 0, Mathf.cos(Mathf.Deg2Rad(40)))
對于d所需方向的距離,請在點計算中包括:向右
d * Vector3(Mathf.sin(Mathf.Deg2Rad(40)), 0, Mathf.cos(Mathf.Deg2Rad(40)))
距離 d 40o:向左距離 d 40o:
d * Vector3(-d * Mathf.sin(Mathf.Deg2Rad(40)), 0, Mathf.cos(Mathf.Deg2Rad(40)))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/482430.html
