【发布时间】:2017-11-28 09:09:03
【问题描述】:
private Vector3 GroundVelocity(ref Vector3 vel)
{
m_animator.SetBool("onGround", true);
Vector2 input = new Vector2(Input.GetAxis("Horizontal"), 0);
bool kbRun = Input.GetKey(KeyCode.LeftShift) && m_controller.isGrounded;
bool gpRun = Mathf.Abs(input.x) > 0.5f && m_controller.isGrounded;
var sortInputType = (Input.GetKey(KeyCode.A) ^ Input.GetKey(KeyCode.D)) ? kbRun : gpRun;
float targetSpeed = ((sortInputType) ? m_runSpeed : m_walkSpeed) * input.x;
m_curSpd = Mathf.SmoothDamp(m_curSpd, targetSpeed, ref m_speedSmoothVelocity, GetModifiedSmoothTime(m_speedSmoothTime * 3) * Time.fixedDeltaTime * m_playerTime);
m_animSpdPer = Mathf.Lerp(0, 1, m_curSpd);
vel = new Vector3(m_curSpd, 0, 0);
return vel;
}
我的角色控制器同时使用游戏手柄和键盘和鼠标配置。以上是我如何获得 CharacterController.Move() 的地面速度。
这个问题是,当我通过“A”和“D”键水平移动时,当统一检测到 A 和 D 都没有按下时,目标速度会暂时设置为 m_runSpeed,然后停止。游戏手柄端按预期工作。我显然需要一种更好的方法来确定布尔值,但我没有想法。
在我看来,如果我可以检测到正在使用的模拟摇杆,我可以这样做,但我认为我的方法不正确。
任何修改或指导的建议都会非常有帮助。谢谢。
【问题讨论】:
标签: unity3d