- Home /
Question by
DocLogic · May 31, 2015 at 08:15 AM ·
standard assets
New FPS Controller - Jump while in-air issue.
When using the new FPS controller from the standard assets in Unity, if I jump while in the air, the character will immediately jump upon landing.
Any solutions to this?
Comment
Best Answer
Answer by Crystalline · May 31, 2015 at 09:49 AM
Create a bool that would be based on Jump inputs , if you hit jump button make the bool true if not make it false ( now the jump script will jump if the bool is true. You can put the jump input checking out of the " if grounded function" , but use the boolean inside the "grounded function".
private void Update()
{
RotateView();
// the jump state needs to read here to make sure it is not missed
if (!m_Jump)
{
m_Jump = CrossPlatformInput$$anonymous$$anager.GetButtonDown("Jump");
canJumpAgain = true;
}
else {
canJumpAgain = false;
}
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
{
StartCoroutine(m_JumpBob.DoBobCycle());
PlayLandingSound();
m_$$anonymous$$oveDir.y = 0f;
m_Jumping = false;
canJumpAgain = true;
}
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
{
m_$$anonymous$$oveDir.y = 0f;
}
m_PreviouslyGrounded = m_CharacterController.isGrounded;
}
and here?
if (m_CharacterController.isGrounded)
{
canJumpAgain = true;
m_$$anonymous$$oveDir.y = -m_StickToGroundForce;
if (m_Jump)
{
m_$$anonymous$$oveDir.y = m_JumpSpeed;
PlayJumpSound();
m_Jump = false;
m_Jumping = true;
}
}