Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vector2 origin = playerPosition;
- Vector2 directionDown = Vector2.down;
- RaycastHit2D[] hits = Physics2D.BoxCastAll(origin, boxSize, 0f, directionDown, distance, layer);
- bool grounded = false;
- bool touchingLeftWall = false;
- bool touchingRightWall = false;
- foreach (var hit in hits)
- {
- Vector2 contactPoint = hit.point;
- float deltaX = contactPoint.x - playerPosition.x;
- float deltaY = contactPoint.y - playerPosition.y;
- if (deltaY < 0f)
- {
- grounded = true;
- }
- else if (deltaX > 0f)
- {
- touchingRightWall = true;
- }
- else if (deltaX < 0f)
- {
- touchingLeftWall = true;
- }
- }
- if (grounded && !touchingLeftWall && !touchingRightWall)
- {
- //pafpafpaf
- }
Advertisement
Add Comment
Please, Sign In to add comment