[英]Why isn't the Move function in Character Controller not moving my player?
So I have a player model with a character controller attached and to manage the player movement I have this file below:所以我有一个带有角色控制器的玩家模型,为了管理玩家的移动,我在下面有这个文件:
using UnityEngine;
public class CharacterMovementController : MonoBehaviour {
Animator characterAnimator;
CharacterController character;
[SerializeField] Transform mainCamera;
[SerializeField] float sprintBoost = 10f;
[SerializeField] float currentSpeed = 20f;
[SerializeField] float trueSpeed;
// Start is called before the first frame update
void Start() {
characterAnimator = gameObject.GetComponent<Animator>();
character = gameObject.GetComponent<CharacterController>();
}
void Update() {
// There was a bunch of animation stuff that I figured wouldn't be important for
// you to read
Vector3 move = new Vector3(Input.GetAxis("Horizontal") * trueSpeed, 0, Input.GetAxis("Vertical") * trueSpeed);
// Movement Logic
character.Move(move * Time.deltaTime);
}
}
I already tried to drag the currentSpeed of the player to insane numbers and still nothing works.我已经尝试将播放器的 currentSpeed 拖到疯狂的数字上,但仍然没有任何效果。 I checked that the character controller is properly being referenced and the Move function is being passed in a Vector3 object
我检查了字符控制器是否被正确引用,并且 Move 函数正在 Vector3 对象中传递
Do not multiply the input value ( Input.GetAxis("Horizontal")
or Input.GetAxis("Vertical")
) with the speed in the move
field, multiply it with the overall vector instead:不要将输入值(
Input.GetAxis("Horizontal")
或Input.GetAxis("Vertical")
)与move
字段中的速度相乘,而是将其与整体矢量相乘:
Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
// Movement Logic
character.Move(move * Time.deltaTime * trueSpeed);
Refer to the CharacterController.Move
documentation for more info有关更多信息,请参阅
CharacterController.Move
文档
所以显然这都是关于步距偏移的,我有一个大模型,我必须缩小很多,这意味着偏移必须非常低,最后我把它设为 0.01
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.