public bool m_controller;
public Vector3 m_velocity;
private float m_curSpd;
private flost m_speedSmoothVelocity;
private Start()
{
m_controller = GetComponent<CharacterController>();
}
private Update()
{
if(m_controller.isGrounded)
{
m_velocity = GroundVelocity();
}
m_controller.Move(m_velocity * Time.fixedDeltaTime);
}
private Vector3 GroundVelocity()
{
if(Input.GetButton("Horizontal"))
{
float inputX = Input.GetAxisRaw("Horizontal");
bool run = Input.GetKey(KeyCode.LeftShift);
float targetVel = ((run) ? m_runSpeed : m_walkSpeed) * inputX;
m_curSpd = Mathf.SmoothDamp(m_curSpd, targetVel, ref m_speedSmoothVelocity, 0.06f);
}
return new Vector3(m_curSpd, 0, 0);
}
私は前にこれを求めてきましたが、唯一のdownvote一切答えは、ありませんでした...Smoothdampは
問題があるおかしな:これは、文字を作るときm_velocity.xが期待から不気味遠くに行動しています歩く。それを見て正常に動作しますが、私は水平キーを押したまま、それを保持して停止m_velocity.xは通常のスローダウンファッションでは0に戻りませんが、その代わりに(値)約5秒間バウンス(m_velocity.xがgetButtonで20だった場合、それは0.xxxから10.xxxのまわりを「片方向ではない」とバウンドします)。
これはバグかsmoothDampの試行が間違っているかどうかはまだ分かりません。私はここで間違って何をしていますか?
にをリセットすることですですあなたはボタンを押したままではありません。実行すべき唯一のコードは 'return new Vector3(m_curSpd、0、0);' – Draco18s
@Draco18sコメントありがとうございます!私はそれを新しいVector(m_curSpd、0、0)として取ることができると思います。これはVector3.zeroが常に返すものです。しかし、私のこの問題は、一度動いていて入力が零になると発生し、奇妙な速度のバウンスが発生します。これはまだ同じですか? –
あなたがしたいことは、 'else'文を設定して' m_curSpd'を0にリセットすることです。 – Draco18s