Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool grounded = true;
- public float JumpSpeed = 100.0f;
- public bool hasJumped = false;
- public Rigidbody rb;
- void jump ()
- {
- if (grounded) {
- rb.AddForce (Vector3.up * JumpSpeed * Time.deltaTime);
- }
- }
- void Update ()
- {
- if (!grounded && rb.velocity.y == 0) {
- grounded = true;
- }
- SimpleMovement sms = gameObject.GetComponent<SimpleMovement> ();
- if (Input.GetButton ("Jump") && grounded == true && sms.canmove) {
- hasJumped = true;
- }
- }
- void FixedUpdate ()
- {
- if (hasJumped) {
- rb.AddForce (Vector3.up * JumpSpeed * Time.deltaTime);
- grounded = false;
- hasJumped = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement