【问题标题】:Script in unity won't change统一的脚本不会改变
【发布时间】: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


【解决方案1】:

检查您是否没有影响 xforce 的 * Time.deltaTime。希望对你有帮助

【讨论】:

  • @M106 如果这是问题,您可以接受答案
猜你喜欢
  • 1970-01-01
  • 2019-12-28
  • 2022-01-21
  • 2022-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-19
  • 2022-10-23
相关资源
最近更新 更多