Advertisement
Guest User

jump

a guest
Aug 31st, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public bool grounded = true;
  2. public float JumpSpeed = 100.0f;
  3. public bool hasJumped = false;
  4. public Rigidbody rb;
  5.  
  6. void jump ()
  7. {
  8. if (grounded) {
  9. rb.AddForce (Vector3.up * JumpSpeed * Time.deltaTime);
  10. }
  11. }
  12.  
  13. void Update ()
  14. {
  15. if (!grounded && rb.velocity.y == 0) {
  16. grounded = true;
  17. }
  18. SimpleMovement sms = gameObject.GetComponent<SimpleMovement> ();
  19. if (Input.GetButton ("Jump") && grounded == true && sms.canmove) {
  20. hasJumped = true;
  21. }
  22. }
  23.  
  24. void FixedUpdate ()
  25. {
  26. if (hasJumped) {
  27. rb.AddForce (Vector3.up * JumpSpeed * Time.deltaTime);
  28. grounded = false;
  29. hasJumped = false;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement