shadow_math_25d.gd 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Adds a simple shadow below an object.
  2. # Place this ShadowMath25D node as a child of a Shadow25D, which
  3. # is below the target object in the scene tree (not as a child).
  4. @tool
  5. @icon("res://addons/node25d/icons/shadow_math_25d_icon.png")
  6. extends CharacterBody3D
  7. class_name ShadowMath25D
  8. # The maximum distance below objects that shadows will appear (in 3D units).
  9. var shadow_length = 1000.0
  10. var _shadow_root: Node25D
  11. var _target_math: Node3D
  12. func _ready():
  13. _shadow_root = get_parent()
  14. var index = _shadow_root.get_index()
  15. if (index > 0): # Else, Shadow is not in a valid place.
  16. _target_math = _shadow_root.get_parent().get_child(index - 1).get_child(0)
  17. func _process(_delta):
  18. if _target_math == null:
  19. if _shadow_root != null:
  20. _shadow_root.visible = false
  21. return # Shadow is not in a valid place or you're viewing the Shadow25D scene.
  22. position = _target_math.position
  23. var k = move_and_collide(Vector3.DOWN * shadow_length)
  24. if k == null:
  25. _shadow_root.visible = false
  26. else:
  27. _shadow_root.visible = true
  28. global_transform = transform