大家好,我的玩家正在石头上行走并穿过石头。名为 Champ 的玩家有一个 Box Collider,而 Stone 有一个 Mesh Collider。玩家也有刚体。我尝试了我发现的一切,但没有任何帮助我解决我的问题。
MovePlayer.cs 脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovePlayer : MonoBehaviour
{
Rigidbody rb;
public float speed = 10f;
private Vector3 moveDirection;
public float rotationSpeed = 0.05f;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")).normalized;
}
void FixedUpdate()
{
rb.MovePosition(rb.position + transform.TransformDirection(moveDirection * speed * Time.deltaTime));
RotatePlayer();
}
void RotatePlayer()
{
if (moveDirection != Vector3.zero)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(moveDirection.normalized), rotationSpeed);
}
transform.Translate(moveDirection * speed * Time.deltaTime, Space.World);
}
}
检查器中的播放器设置 https://i.stack.imgur.com/bZyWq.png
检查器中的石材设置 https://i.stack.imgur.com/HwsQA.png
场景预览 https://i.stack.imgur.com/XXZPm.png
谢谢你们的帮助! :)
所以我在上面发布的人的帮助下找到了解决方案。
问题是我的播放器速度在代码中太高,速度为 float 10,但我将 Player 的 Unity Inspector 中的速度更改为 float 50。
所以我解决问题的第一步是将速度设置为float 10,但我仍然想以50f的速度移动......
此问题的解决方案是,在 Unity 2020.3.24f1 及更高版本(可能更低)中,您可以转到编辑>项目设置>物理并设置“默认最大爆破速度“以你希望物体停止而不通过的速度。就我而言,我想移动速度 = 50f所以我需要改变默认最大爆破速度 to 50.
我希望我将来可以帮助别人回答这个问题!
最好的祝愿
马克斯·G。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)