Question by
SeikenFlame · Oct 26, 2018 at 04:29 PM ·
double jump
How to make a proper double jump with my code?
I have some trouble wto do a double jump with my character. First, he seems to have some resistance. Also, my character can jump a maximum of 2 times, but he doesn't want to do any other jump thereafter. What's the solution?
public bool IsGrounded = true;
public int numberjump = 0;
private bool facingright = true;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetAxisRaw("Horizontal") < -0.5f)
{
this.gameObject.GetComponent<Rigidbody2D>().AddForce(transform.right * -10);
if (Input.GetKey (KeyCode.LeftShift))
{
this.gameObject.GetComponent<Rigidbody2D>().AddForce(transform.right * -20);
}
}
if (Input.GetAxisRaw("Horizontal") > 0.5f)
{
this.gameObject.GetComponent<Rigidbody2D>().AddForce(transform.right * 10);
if (Input.GetKey(KeyCode.LeftShift))
{
this.gameObject.GetComponent<Rigidbody2D>().AddForce(transform.right * 20);
}
}
if (Input.GetButtonDown("Jump") && IsGrounded == false)
{
this.gameObject.GetComponent<Rigidbody2D>().AddForce(transform.up * 300);
numberjump++;
if (numberjump >= 2)
{
IsGrounded = true;
}
}
}
void Flip()
{
facingright = !facingright;
transform.Rotate(Vector3.up * 180);
}
void OnCollisionEnter(Collision CL)
{
numberjump = 0;
IsGrounded = false;
}
}
Comment
Your answer
Follow this Question
Related Questions
Double Jump Not Working Good 1 Answer
Double Jump Unity 1 Answer
DoubleJump 1 Answer
2d Platformer double jump wont work 2 Answers
Please help me with my double jump error 0 Answers