c# - 玩家在 Unity 中不动
问题描述
这是我的代码:
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
// This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;
public float forwardForce = 4000f;
public float sidewaysForce = 100f;
// We marked this as "Fixed"Update because we
// are using it to mess with physics.
void FixedUpdate()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if( Input.GetKey("d") )
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if( Input.GetKey("a") )
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
}
请帮忙。
解决方案
让我们尝试一些事情。首先,尝试在 FixedUpdate 中取出 Time.deltaTime。在 FixedUpdate 中添加力时,通常不需要使用Time.deltaTime。
其次,尝试创建一个零摩擦的物理材质并将其附加到玩家对象的盒子碰撞器上。
推荐阅读
- javascript - iOS iPhone 11 在浏览器不断重新加载时闪烁黑白:RBS 后台断言 ConnectionTerminationWatchdog
- javascript - 循环浏览我上传的文件
- python - 用python切片和追加
- c# - C# WPF 条件事件触发
- c - 没有错误或警告的分段错误(核心转储)
- ffmpeg - ffmpeg 计时元数据值与 ffprobe 输出不同
- c - fgets() 没有得到输入
- javascript - Javascript按日期字段对数组进行排序
- javascript - 如何从 Angular 11 组件访问 chrome api
- sql - sqlite 从 group by 中获取总行数