mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-07 16:30:06 +01:00
This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions. The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declration warnings. Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).
29 lines
569 B
GDScript
29 lines
569 B
GDScript
extends Control
|
|
|
|
@export var world_offset := Vector3.ZERO
|
|
|
|
var _pos_offset: Vector2
|
|
var _attachment: Node3D
|
|
|
|
func _ready() -> void:
|
|
_pos_offset = position
|
|
_attachment = get_parent()
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
if _attachment == null:
|
|
return
|
|
|
|
var viewport := get_viewport()
|
|
if viewport == null:
|
|
return
|
|
|
|
var camera := viewport.get_camera_3d()
|
|
if camera == null:
|
|
return
|
|
|
|
var world_pos := world_offset + _attachment.global_transform.origin
|
|
var screen_pos := camera.unproject_position(world_pos)
|
|
|
|
position = _pos_offset + screen_pos - 0.5 * size
|