Question by
Segy · Feb 09, 2016 at 02:05 PM ·
double jump
double jump not working when off fall off the edge
Below is my script. I am making a 2D platform running game. My player is able to do double jump. However, when I fall off the edge of the platform i can only do 1 jump.
My script is only saying to double jump when I am grounded. I want to be able to do double when I am grounded and when i am not.
Thankyou
// Use this for initialization
void Awake()
{
myRigidbody = GetComponent<Rigidbody2D>();
myCollider = GetComponent<CircleCollider2D>();
theScoreManager = FindObjectOfType<ScoreManager>();
speedMilestoneCount = speedIncreaseMilestone;
moveSpeedStore = moveSpeed;
speedMilestoneCountStore = speedMilestoneCount;
speedIncreaseMilestoneStore = speedIncreaseMilestone;
jumpTimeCounter = jumpTime;
stoppedJumping = true;
}
// Update is called once per frame
void Update()
{
grounded = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);
if (Input.GetMouseButtonDown(0))
{
if (grounded)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
stoppedJumping = false;
}
else if (!grounded && canDoubleJump)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
jumpTimeCounter = jumpTime;
stoppedJumping = false;
canDoubleJump = false;
}
}
}
public void FixedUpdate()
{
if ((Input.GetMouseButton(0)) && !stoppedJumping)
{
if (jumpTimeCounter > 0)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
jumpTimeCounter -= Time.deltaTime;
}
}
if (Input.GetMouseButtonUp(0))
{
jumpTimeCounter = 0;
stoppedJumping = true;
}
if (grounded)
{
jumpTimeCounter = jumpTime;
canDoubleJump = true;
}
}
}
Comment