[英]Time.deltaTime and Axis Input
我有一個簡單的問題。 假設我想通過使用Vector2速度變量轉換角色來移動角色,該變量將從Input.GetAxis獲取其值。 當我這樣編寫代碼時:
Vector2 input=new Vector2(Input.GexAxis("Horizontal"), Input.GetAxis("Vertical"));
velocity.x=input.x* Time.deltaTime * moveSpeed;
velocity.y+=gravityTime.deltaTime;
transform.Translate(velocityTime.deltaTime);
我收到一個奇怪的錯誤,其中我的角色幾乎沒有移動(移動但非常緩慢,而且口吃很多)。 但是,從Velocity.x中刪除Time.deltaTime時,我可以正常工作。 我知道Time.deltaTime是什么,它的用途是什么,但是我不確定為什么不能將它與input.x一起使用,但可以在重力作用下使用它嗎?
btw moveSpeed和gravity只是具有公開分配值的float變量。
您可以使用更簡單(但數量更多)的代碼來實現移動。
if (Input.GetKey(KeyCode.W))
{
gameObject.transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
只需對每個方向重復此操作即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.