[英]movement with 3D sprite in unity is not working
我已經用我的幽靈(一個紅球)完成了所有運動,所以我制作了一個精靈(我不確定這是否是你所說的)我能夠制作一個但現在運動不起作用。 它看起來像是在冰上,因為當它試圖轉彎時,它會變成對角線,而直行時會加速。 我不知道它為什么這樣做,因為我什至沒有用力來移動它。 (編碼):
GameObject.Find("ghosteyes").transform.position = (place + vecmove);
謝謝
所以你可以做的是三件事。 首先獲取您的轉換,然后使用 Translate 移動它,如下所示:
private Transform _transform;
private void Start()
{
//this gets the transform that the script is on and sets it to _transform
_transform = this.GetComponent<Transform>();
}
private void Update()
{
float hor = Input.GetAxis("Horizontal");
float vert = Input.GetAxis("Vertical");
_transform.Translate(new Vector2(hor, vert));
}
或將輸入添加到位置以獲得更固定的移動。
私有轉換_transform;
private void Start()
{
//this gets the transform that the script is on and sets it to _transform
_transform = this.GetComponent<Transform>();
}
private void Update()
{
float hor = Input.GetAxis("Horizontal");
float vert = Input.GetAxis("Vertical");
_transform.position += new Vector3(hor,vert) * Time.deltaTime;
}
或者
在您的播放器上創建一個剛體。 然后將此腳本放在您的播放器上。 並使用rigidbody.MovePosition 移動你的角色。 例如:
private Rigidbody2D rb;
private void Start()
{
rb = this.GetComponent<Rigidbody>();
}
private void Update()
{
//This will take in horizontal input like A and D/ arrow left or right.
float hor = Input.GetAxis("Horizontal");
rb.MovePosition(transform.position += new Vector2(hor,0));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.