2014-10-03 05:10:51 +02:00
|
|
|
|
|
|
|
extends Camera
|
|
|
|
|
2015-12-09 08:38:23 +01:00
|
|
|
# member variables
|
|
|
|
var collision_exception = []
|
|
|
|
export var min_distance = 0.5
|
|
|
|
export var max_distance = 4.0
|
|
|
|
export var angle_v_adjust = 0.0
|
|
|
|
export var autoturn_ray_aperture = 25
|
|
|
|
export var autoturn_speed = 50
|
2014-10-03 05:10:51 +02:00
|
|
|
var max_height = 2.0
|
|
|
|
var min_height = 0
|
|
|
|
|
2015-12-09 08:38:23 +01:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
func _fixed_process(dt):
|
2015-12-09 08:38:23 +01:00
|
|
|
var target = get_parent().get_global_transform().origin
|
2014-10-03 05:10:51 +02:00
|
|
|
var pos = get_global_transform().origin
|
2015-12-09 08:38:23 +01:00
|
|
|
var up = Vector3(0, 1, 0)
|
2014-10-03 05:10:51 +02:00
|
|
|
|
|
|
|
var delta = pos - target
|
|
|
|
|
2015-12-09 08:38:23 +01:00
|
|
|
# regular delta follow
|
2014-10-03 05:10:51 +02:00
|
|
|
|
2015-12-09 08:38:23 +01:00
|
|
|
# check ranges
|
2014-10-03 05:10:51 +02:00
|
|
|
if (delta.length() < min_distance):
|
2015-12-09 08:38:23 +01:00
|
|
|
delta = delta.normalized()*min_distance
|
2014-10-03 05:10:51 +02:00
|
|
|
elif (delta.length() > max_distance):
|
2015-12-09 08:38:23 +01:00
|
|
|
delta = delta.normalized()*max_distance
|
2014-10-03 05:10:51 +02:00
|
|
|
|
2015-12-09 08:38:23 +01:00
|
|
|
# check upper and lower height
|
2014-10-03 05:10:51 +02:00
|
|
|
if ( delta.y > max_height):
|
|
|
|
delta.y = max_height
|
|
|
|
if ( delta.y < min_height):
|
|
|
|
delta.y = min_height
|
2015-12-09 08:38:23 +01:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
pos = target + delta
|
|
|
|
|
2015-12-09 08:38:23 +01:00
|
|
|
look_at_from_pos(pos, target, up)
|
2014-10-03 05:10:51 +02:00
|
|
|
|
2015-12-09 08:38:23 +01:00
|
|
|
# turn a little up or down
|
2014-10-03 05:10:51 +02:00
|
|
|
var t = get_transform()
|
2015-12-09 08:38:23 +01:00
|
|
|
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
2014-10-03 05:10:51 +02:00
|
|
|
set_transform(t)
|
|
|
|
|
|
|
|
|
2015-12-09 08:38:23 +01:00
|
|
|
func _ready():
|
|
|
|
# find collision exceptions for ray
|
2014-10-03 05:10:51 +02:00
|
|
|
var node = self
|
|
|
|
while(node):
|
|
|
|
if (node extends RigidBody):
|
|
|
|
collision_exception.append(node.get_rid())
|
|
|
|
break
|
|
|
|
else:
|
2015-12-09 08:38:23 +01:00
|
|
|
node = node.get_parent()
|
2014-10-03 05:10:51 +02:00
|
|
|
set_fixed_process(true)
|
2015-12-09 08:38:23 +01:00
|
|
|
# this detaches the camera transform from the parent spatial node
|
2014-10-03 05:10:51 +02:00
|
|
|
set_as_toplevel(true)
|