@@ -4,7 +4,7 @@ extends Camera
44# Member variables
55var collision_exception = []
66export var min_distance = 0.5
7- export var max_distance = 4.0
7+ export var max_distance = 3.5
88export var angle_v_adjust = 0.0
99export var autoturn_ray_aperture = 25
1010export var autoturn_speed = 50
@@ -15,33 +15,33 @@ func _physics_process(dt):
1515 var target = get_parent ().get_global_transform ().origin
1616 var pos = get_global_transform ().origin
1717 var up = Vector3 (0 , 1 , 0 )
18-
18+
1919 var delta = pos - target
20-
20+
2121 # Regular delta follow
22-
22+
2323 # Check ranges
2424 if delta .length () < min_distance :
2525 delta = delta .normalized () * min_distance
2626 elif delta .length () > max_distance :
2727 delta = delta .normalized () * max_distance
28-
28+
2929 # Check upper and lower height
3030 if delta .y > max_height :
3131 delta .y = max_height
3232 if delta .y < min_height :
3333 delta .y = min_height
34-
34+
3535 # Check autoturn
3636 var ds = PhysicsServer .space_get_direct_state (get_world ().get_space ())
37-
37+
3838 var col_left = ds .intersect_ray (target , target + Basis (up , deg2rad (autoturn_ray_aperture )).xform (delta ), collision_exception )
3939 var col = ds .intersect_ray (target , target + delta , collision_exception )
4040 var col_right = ds .intersect_ray (target , target + Basis (up , deg2rad (- autoturn_ray_aperture )).xform (delta ), collision_exception )
41-
41+
4242 if ! col .empty ():
4343 # If main ray was occluded, get camera closer, this is the worst case scenario
44- delta = col .position - target
44+ delta = col .position - target
4545 elif ! col_left .empty () and col_right .empty ():
4646 # If only left ray is occluded, turn the camera around to the right
4747 delta = Basis (up , deg2rad (- dt * autoturn_speed )).xform (delta )
@@ -51,15 +51,15 @@ func _physics_process(dt):
5151 else :
5252 # Do nothing otherwise, left and right are occluded but center is not, so do not autoturn
5353 pass
54-
54+
5555 # Apply lookat
5656 if delta == Vector3 ():
5757 delta = (pos - target ).normalized () * 0.0001
5858
5959 pos = target + delta
60-
60+
6161 look_at_from_position (pos , target , up )
62-
62+
6363 # Turn a little up or down
6464 var t = get_transform ()
6565 t .basis = Basis (t .basis [0 ], deg2rad (angle_v_adjust )) * t .basis
0 commit comments