user6768003 user6768003 - 3 months ago 12
C# Question

How can i double jump using a character controller component

How do i make my player with a character controller component double jump, with a rigidbody is easier because it handles the physics but i use character controller because it gives me more control over the player, here is my script:

public void AddGravity()
{
if (!Inputter.Body.isGrounded)
{
Inputter.Movement_Dir.y -= Inputter.Gravity;
Inputter.Speed = Inputter.Un_Grounded_Speed;
}
else
Inputter.Movement_Dir.y = 0f;
}

public void Jump()
{
if (Inputter.Jump)
{
if (Inputter.Body.isGrounded)
{
Inputter.Movement_Dir.y = Inputter.Jump_Height;
Inputter.Double_Jump = true;
}
else if (Inputter.Double_Jump)
{
Inputter.Movement_Dir.y = Inputter.Jump_Height;
Inputter.Double_Jump = false;
}
}
}


then i just call the methods from the inputter class.

Answer

It works basically the same as rigidbody, you make a boolean called double jump, and when you touch the ground it sets as false, when you jump for the first time its set to true.for jumping you check if (jump button){if(grounded || doublejump) then jump}

Comments