shadow_math_25d.gd 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  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. extends KinematicBody
  6. class_name ShadowMath25D, "res://addons/node25d/icons/shadow_math_25d_icon.png"
  7. # The maximum distance below objects that shadows will appear (in 3D units).
  8. var shadow_length = 1000.0
  9. var _shadow_root: Node25D
  10. var _target_math: Spatial
  11. func _ready():
  12. _shadow_root = get_parent()
  13. var index = _shadow_root.get_position_in_parent()
  14. if (index > 0): # Else, Shadow is not in a valid place.
  15. _target_math = _shadow_root.get_parent().get_child(index - 1).get_child(0)
  16. func _process(_delta):
  17. if _target_math == null:
  18. if _shadow_root != null:
  19. _shadow_root.visible = false
  20. return # Shadow is not in a valid place or you're viewing the Shadow25D scene.
  21. translation = _target_math.translation
  22. var k = move_and_collide(Vector3.DOWN * shadow_length)
  23. if k == null:
  24. _shadow_root.visible = false
  25. else:
  26. _shadow_root.visible = true
  27. global_transform = transform