[英]Camera moving on X axis but not Y axis
我有一個腳本,因此Main Camera
將在x
軸上移動。 這樣很好。 然后我有一個不同的場景,我希望相機跟隨鼠標在x
和y
軸上移動。 所以我做了一個新的腳本,我的代碼看起來像這樣
transform.position = newvector3.Movetowards(
Input.GetAxisRaw("mouse X") * speed * Time.DeltaTime,
0f,
Input.GetAxisRaw("mouse Y") * speed* Time.DeltaTime
);
它在x
軸上精細移動,但在y
軸上完全不移動。 有人知道為什么嗎?
我認為,如果您不知道目標是哪個,MoveTowards並不是改變位置的最佳方法。 您只需在坐標上增加一個增量:
transform.position += new Vector3(
Input.GetAxisRaw("mouse X") * speed * Time.DeltaTime,
0f,
Input.GetAxisRaw("mouse Y") * speed* Time.DeltaTime
);
如果位置不能增加,請糾正我。 這將在X和Z軸上移動對象。
你有嘗試過嗎?
transform.position = newvector3.Movetowards(
Input.GetAxisRaw("mouse X") * speed * Time.DeltaTime,
Input.GetAxisRaw("mouse Y") * speed* Time.DeltaTime,
0f
);
您不確定這是否可行,請嘗試一下
public float speed;
private void Update()
{
Vector3 someVector3;
someVector3.x = Input.GetAxisRaw("mouse x") * speed * Time.deltaTime;
someVector3.y = Input.GetAxisRaw("mouse y") * speed * Time.deltaTime;
someVector3.z = 0;
transform.position += someVector3;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.