This commit is contained in:
team3
2026-09-16 17:55:38 +02:00
parent c9416ed3c6
commit f012dd7cd5
17 changed files with 878 additions and 160 deletions

View File

@@ -11,6 +11,7 @@ var distance := 46.0
var _cam: Camera3D
var _focus := Vector3.ZERO
var blocked := false ## zuletzt an einem Hindernis abgefangen
func _ready() -> void:
_cam = Camera3D.new()
@@ -51,11 +52,26 @@ func _process(delta: float) -> void:
if target:
_focus = _focus.lerp(target.global_position, clampf(delta * 5.0, 0.0, 1.0))
blocked = false
position = _focus
var dir := Vector3(0, 0, 1).rotated(Vector3.RIGHT, pitch).rotated(Vector3.UP, yaw)
_cam.position = dir * distance
var wanted: Vector3 = dir * distance
_cam.position = _clip_to_view(wanted)
_cam.look_at(global_position + Vector3(0, 2.5, 0), Vector3.UP)
## Zieht die Kamera vor ein Hindernis, statt hindurchzuschauen.
func _clip_to_view(local_target: Vector3) -> Vector3:
var from: Vector3 = global_position + Vector3(0, 2.5, 0)
var to: Vector3 = global_position + local_target
var space := get_world_3d().direct_space_state
var q := PhysicsRayQueryParameters3D.create(from, to, 2)
var hit := space.intersect_ray(q)
if hit.is_empty():
return local_target
var p: Vector3 = hit["position"] + (from - hit["position"]).normalized() * 0.7
blocked = true
return p - global_position
func snap_to(p: Vector3) -> void:
_focus = p
position = p