【发布时间】:2021-05-22 01:57:40
【问题描述】:
public class sphere : MonoBehaviour
{
bool jump;
Rigidbody rig;
float horizontalInput;
// Start is called before the first frame update
void Start()
{
rig = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
jump = true;
horizontalInput = Input.GetAxis("Horizontal");
}
private void FixedUpdate()
{
if (jump)
{
rig.AddForce(Vector3.up * 3, ForceMode.VelocityChange);
jump = false;
}
GetComponent<Rigidbody>().velocity = new Vector3(horizontalInput*3, 0, 0);
}
}
在这里,当我按下 play 时,每当我的球跳跃时,它都会非常缓慢地跳跃,好像有什么东西在试图反对它。此外,当它下降时,它下降得太慢了。
谁能解释这里发生了什么并提出解决方案。
【问题讨论】:
-
你能发布更多代码吗?这个 sn-p 将您的 x 速度设置为
horizontalInput,其余设置为 0。没有垂直运动,所以没有跳跃......
标签: unity3d