Guest User

Untitled

a guest
Jun 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Playermovement : MonoBehaviour
  6. {
  7. public Rigidbody rb;
  8.  
  9. void Start ()
  10. }
  11.  
  12. void Update()
  13. {
  14. bool player_jump = Input.GetButtonDown("DefaultJump");
  15. if (player_jump)
  16. {
  17. rb.AddForce(Vector3.up * 365f);
  18. }
  19. }
  20. }
  21. }
  22.  
  23. private Rigidbody rb;
  24. bool isGrounded = true;
  25. public float jumpForce = 20f;
  26.  
  27. void Start()
  28. {
  29. rb = GetComponent<Rigidbody>();
  30. }
  31.  
  32. private void Update()
  33. {
  34. bool player_jump = Input.GetButtonDown("DefaultJump");
  35.  
  36. if (player_jump && isGrounded)
  37. {
  38. rb.AddForce(Vector3.up * jumpForce);
  39. }
  40. }
  41.  
  42. void OnCollisionEnter(Collision collision)
  43. {
  44. if (collision.gameObject.CompareTag("Ground"))
  45. {
  46. isGrounded = true;
  47. }
  48. }
  49.  
  50.  
  51. void OnCollisionExit(Collision collision)
  52. {
  53. if (collision.gameObject.CompareTag("Ground"))
  54. {
  55. isGrounded = false;
  56. }
  57. }
  58.  
  59. private Rigidbody rb;
  60. public float jumpForce = 20f;
  61.  
  62. void Start()
  63. {
  64. rb = GetComponent<Rigidbody>();
  65. }
  66.  
  67. private void Update()
  68. {
  69. bool player_jump = Input.GetButtonDown("DefaultJump");
  70.  
  71. if (player_jump && IsGrounded())
  72. {
  73. rb.AddForce(Vector3.up * jumpForce);
  74. }
  75. }
  76.  
  77. bool IsGrounded()
  78. {
  79. RaycastHit hit;
  80. float raycastDistance = 10;
  81. //Raycast to to the floor objects only
  82. int mask = 1 << LayerMask.NameToLayer("Ground");
  83.  
  84. //Raycast downwards
  85. if (Physics.Raycast(transform.position, Vector3.down, out hit,
  86. raycastDistance, mask))
  87. {
  88. return true;
  89. }
  90. return false;
  91. }
Add Comment
Please, Sign In to add comment