Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. //This is a layer that you set up for ground, layers are next to tags on the inspector and you will often need to add one
  2. //The advantage to this is that you can change the layer of several objects to ground and not have to worry about tags or string checks
  3. //To see if your player is on the ground
  4. public LayerMask groundLayer;
  5. //This is the trigger2d collider you add under your players feet so you can easily debug where the box that is supposed to be doing
  6. //ground checks are. While you can declare the size of a box in the physics check I find it easier for new people to be able to see
  7. //the scale
  8. public BoxCollider2D thisGroundCol;
  9. //A simple float we trip back and forth so that the behavior can know if our player is touching the ground, any ground.
  10. public float isGrounded;
  11.  
  12. public void Update()
  13. {
  14. isGrounded = Physics2D.IsTouchingLayers(thisGroundCol, groundLayer)
  15. if (Input.GetKeyDown("up") && isGrounded)
  16. {
  17. rigidbody2d.velocity = Vector2.up * jumpheight;
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement