Eonirr

Untitled

Feb 1st, 2026
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. Vector2 origin = playerPosition;
  2. Vector2 directionDown = Vector2.down;
  3.  
  4. RaycastHit2D[] hits = Physics2D.BoxCastAll(origin, boxSize, 0f, directionDown, distance, layer);
  5.  
  6. bool grounded = false;
  7. bool touchingLeftWall = false;
  8. bool touchingRightWall = false;
  9.  
  10. foreach (var hit in hits)
  11. {
  12. Vector2 contactPoint = hit.point;
  13.  
  14. float deltaX = contactPoint.x - playerPosition.x;
  15. float deltaY = contactPoint.y - playerPosition.y;
  16.  
  17. if (deltaY < 0f)
  18. {
  19. grounded = true;
  20. }
  21. else if (deltaX > 0f)
  22. {
  23. touchingRightWall = true;
  24. }
  25. else if (deltaX < 0f)
  26. {
  27. touchingLeftWall = true;
  28. }
  29. }
  30.  
  31. if (grounded && !touchingLeftWall && !touchingRightWall)
  32. {
  33. //pafpafpaf
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment