【发布时间】:2018-12-23 11:46:30
【问题描述】:
我制作了一个使用 .AddForce 移动球的脚本。当我在 z 轴上使用它时,它工作正常,但是当我在 x 轴上移动时,它走得太快了。 x 轴的速度过去是 300,但我将两者都更改为 50。 x 轴上的力仍然太高,不会改变。
using UnityEngine;
public class ball_movement : MonoBehaviour
{
public Rigidbody ballmovement;
public float zforce = 50f;
public float xforce = 50f;
private void FixedUpdate()
{
if (Input.GetKey("w"))
{
//ball moves right
ballmovement.AddForce(0, 0, zforce * Time.deltaTime,
ForceMode.VelocityChange);
}
if (Input.GetKey("s"))
{
//ball moves left
ballmovement.AddForce(0, 0, -zforce * Time.deltaTime,
ForceMode.VelocityChange);
}
if (Input.GetKey("d"))
{
//ball moves forward
ballmovement.AddForce(xforce, 0, 0 * Time.deltaTime,
ForceMode.VelocityChange);
}
if (Input.GetKey("a"))
{
//ball moves right
ballmovement.AddForce(-xforce, 0, 0 * Time.deltaTime,
ForceMode.VelocityChange);
}
}
}
我做错了什么?
【问题讨论】:
-
如果以下答案之一解决了您的问题,您应该接受它(单击相应答案旁边的复选标记)。这有两件事。它让每个人都知道您的问题已得到您满意的解决,并为帮助您的人提供帮助。 See here 以获得完整的解释。
标签: unity3d