- Home /
Question by
Bunnehop0923 · Dec 03, 2020 at 12:21 AM ·
double jump
double jump won't work pls help
public class doublejump : MonoBehaviour
{
private Rigidbody2D rb2d;
public float jumpower;
public bool isgrounded;
public Transform groundcheck;
public float groundcheckradius;
public LayerMask whatisground;
public bool candoublejump;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
void jump()
{
rb2d.velocity = new Vector2(rb2d.velocity.x, jumpower);
}
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
if(isgrounded)
{
jump();
candoublejump = true;
}
else if(candoublejump)
{
jump();
candoublejump = false;
}
}
}
private void FixedUpdate()
{
isgrounded = Physics2D.OverlapCircle(groundcheck.position,groundcheckradius,whatisground);
}
private void OnDrawGizmos()
{
Gizmos.DrawWireSphere(groundcheck.position, groundcheckradius);
}
}
Comment
got this from a tutorial every thing else works fine except the double jump
Best Answer
Answer by PersianKiller · Dec 03, 2020 at 06:06 AM
i think it's because you are using GetKey and it jumps 2 times at the moment,you should use GetKeyDown :)
Your answer
Follow this Question
Related Questions
restrict number of double jumps 1 Answer
2D Character Controller Double Jump? 1 Answer
Counter for double jump don't work 1 Answer
third person double jump 0 Answers