Skip to content

Commit

Permalink
Double Jump
Browse files Browse the repository at this point in the history
Doule Jump and remapping
  • Loading branch information
aps16104 committed Apr 14, 2020
1 parent 739f87b commit 91d863d
Show file tree
Hide file tree
Showing 2 changed files with 110,804 additions and 23,787 deletions.
40 changes: 28 additions & 12 deletions Platformer/Assets/Scripts/Player_Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

public class Player_Controller : MonoBehaviour
{
public float speed = 5f;
public float speed = 7.5f;
public Rigidbody2D rb;

public int jumps;
int maxjumps = 2;
float jumpforce = 8.75f;
bool grounded = true;

void Start()
{
rb = GetComponent<Rigidbody2D>(); //Get other component
rb = GetComponent<Rigidbody2D>(); //Get rigidbody component from player
}

void Update()
Expand All @@ -19,23 +24,34 @@ void Update()
Vector3 movement = new Vector3(moveHorizontal, 0.0f, 0.0f); //No movement in the Y or Z Axies
transform.position += movement * Time.deltaTime * speed; //Transform the position in accordance to movement, times speed, times time passed




if (Input.GetKeyDown(KeyCode.Space))
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.W))
{
rb.velocity = new Vector3(rb.velocity.x, 10f, 0.0f);
Jump();
}

}

private void OnTriggerEnter2D(Collider2D other)
void Jump()
{
if (other.gameObject.CompareTag("Box"))
if (jumps > 0)
{
rb.AddForce(new Vector2(0, jumpforce), ForceMode2D.Impulse);
grounded = false;
jumps = jumps - 1;
}
if (jumps == 0)
{

return;
}
}


}
void OnCollisionEnter2D(Collision2D collide)
{
if (collide.gameObject.tag == "Box")
{
jumps = maxjumps;
grounded = true;
}
}

}
Loading

0 comments on commit 91d863d

Please sign in to comment.