control3d.gd 536 B

123456789101112131415161718192021222324252627282930
  1. extends Control
  2. @export var world_offset = Vector3.ZERO
  3. var _pos_offset
  4. var _attachment
  5. func _ready():
  6. _pos_offset = position
  7. _attachment = get_parent() as Node3D
  8. func _process(_delta):
  9. if _attachment == null:
  10. return
  11. var viewport = get_viewport()
  12. if viewport == null:
  13. return
  14. var camera = viewport.get_camera_3d()
  15. if camera == null:
  16. return
  17. var world_pos = world_offset + _attachment.global_transform.origin
  18. var screen_pos = camera.unproject_position(world_pos)
  19. position = _pos_offset + screen_pos - 0.5 * size