LedgeDetectionCast.gd 549 B

1234567891011121314151617181920212223
  1. class_name LedgeDetectionCast
  2. extends RayCast2D
  3. @export var floor_normal := Vector2.UP
  4. @export var ray_length := 24
  5. var floor_direction := 1
  6. var direction := 1
  7. ## Hypotenuse = floor_angle
  8. ## Opposite = ???
  9. ## Adjacent = position.x
  10. func _physics_process(_delta: float) -> void:
  11. target_position.y = ray_length
  12. if floor_normal.x > 0:
  13. floor_direction = 1
  14. elif floor_normal.x < 0:
  15. floor_direction = -1
  16. else:
  17. position.y = -(ray_length / 2.0)
  18. return
  19. position.y = ((-floor_normal.y * (position.x)) * (floor_direction)) - (ray_length / 2.0)