c# - 如何使用rigidbody.moveposition移动玩家,但将玩家移动到他正在寻找的位置并根据该移动玩家?
问题描述
到目前为止,这是我的播放器控制器脚本..'''
//Variables
public float speed = 5f;
public float sprintSpeed = 10f;
public float jumpForce = 10f;
private Rigidbody rb;
//Methods
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
BasicMovement();
}
void BasicMovement()
{
//Get Player Input
float inputX = Input.GetAxis("Horizontal");
float inputZ = Input.GetAxis("Vertical");
//Get where is Player moving position
Vector3 direction = new Vector3(inputX, 0f, inputZ);
//Move Player
rb.MovePosition(transform.localPosition + (direction * speed * Time.deltaTime));
}
'''
凸轮控制器脚本:''' //变量 public float mouseSensitivity = 100f; //鼠标灵敏度变量,以便我稍后可以将其更改为我喜欢的 public Transform playerBody; //所以camera知道什么是player body private float xAxisRotation; //沿x轴移动
void Start()
{
}
void FixedUpdate()
{
Cursor.lockState = CursorLockMode.Locked; //Locks mouse cursor at the center of the screen
//Get Mouse X,Y positions in variables
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; //Gets mouse location at the x-axis
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; //Gets mouse location at the y-axis
xAxisRotation -= mouseY; //-ensures the rotation is not flipped
xAxisRotation = Mathf.Clamp(xAxisRotation, -90f, 90f); //Clamps rotation to -90, 90 so that player cannot look behind
transform.localRotation = Quaternion.Euler(xAxisRotation, 0f, 0f); //I dont know
//Implement mouseX position to playerBody so that the entire player moves in the X-Axis
playerBody.Rotate(Vector3.up * mouseX);
}
'''
如果您需要其他东西请告诉。
解决方案
推荐阅读
- python - Python PL/SQL 使日期成为每天都在变化的变量
- amazon-web-services - 无法弄清楚 Lambda 重试
- solana - 如何在 Anchor 上升级程序 ID
- excel - 如何避免power查询出现“文件名超过系统定义的最大长度”的错误?
- python - 我正在尝试使用 python selenium 启动 chrome 特定配置文件?
- reactjs - 通过本地反应应用程序从 Google 表格中获取数据的响应不一致
- c++ - 有没有办法打印通常分配给指针数组的整数?
- python - fastapi、html 和表单。如何不加载新页面?
- json - Windows Jenkins master 无法在 Linux 代理上正确执行作业
- css - React Native 中带有换行符的多个文本组件