Character Controller有时无法移动
unity3d吧
全部回复
仅看楼主
level 6
Great小卢XL 楼主
当我的摄像机的X轴逐渐增大,速度也就越慢。代码在下(全部的代码)
谁能告诉我为什么,怎么解决?
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
public Vector3 moveDirection = Vector3.zero;
void FixedUpdate()
{
CharacterController controller = GetComponentInParent<CharacterController>();
if (controller.isGrounded == true)
{
moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetKey(KeyCode.Space))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
2018年11月12日 14点11分 1
level 13
在update里getcomponent就不用往下看了[汗]
2018年11月12日 15点11分 2
还是看了看[小乖]仅靠重力作用,地不平的话isgrounded大部分情况下是false的
2018年11月12日 15点11分
地是平的,还有我不太明白“在update里getcomponent就不用往下看了”是什么意思
2018年11月13日 13点11分
@Great小卢XL getcomponent是非常消耗性能的,还可能出现一些异常结果。你使用的都是同一个charactercontroller,只要在Start里获取一次就行了
2018年11月13日 13点11分
我录一段视频给你看看吧
2018年11月13日 13点11分
level 6
Great小卢XL 楼主
2018年11月13日 13点11分 3
level 13
那你相机呢。怎么挂的?脚本怎么写的?发全啊倒是。
2018年11月13日 13点11分 4
level 6
Great小卢XL 楼主
2018年11月13日 13点11分 5
1