2014-10-03 03:10:51 +00:00
|
|
|
|
|
|
|
extends Camera
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Member variables
|
2015-12-09 07:38:23 +00:00
|
|
|
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 03:10:51 +00:00
|
|
|
var max_height = 2.0
|
|
|
|
var min_height = 0
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2014-10-03 03:10:51 +00:00
|
|
|
func _fixed_process(dt):
|
2015-12-09 07:38:23 +00:00
|
|
|
var target = get_parent().get_global_transform().origin
|
2014-10-03 03:10:51 +00:00
|
|
|
var pos = get_global_transform().origin
|
2015-12-09 07:38:23 +00:00
|
|
|
var up = Vector3(0, 1, 0)
|
2014-10-03 03:10:51 +00:00
|
|
|
|
|
|
|
var delta = pos - target
|
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Regular delta follow
|
2014-10-03 03:10:51 +00:00
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Check ranges
|
2014-10-03 03:10:51 +00:00
|
|
|
if (delta.length() < min_distance):
|
2015-12-09 07:38:23 +00:00
|
|
|
delta = delta.normalized()*min_distance
|
2014-10-03 03:10:51 +00:00
|
|
|
elif (delta.length() > max_distance):
|
2015-12-09 07:38:23 +00:00
|
|
|
delta = delta.normalized()*max_distance
|
2014-10-03 03:10:51 +00:00
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Check upper and lower height
|
2014-10-03 03:10:51 +00:00
|
|
|
if ( delta.y > max_height):
|
|
|
|
delta.y = max_height
|
|
|
|
if ( delta.y < min_height):
|
|
|
|
delta.y = min_height
|
2015-12-09 07:38:23 +00:00
|
|
|
|
2014-10-03 03:10:51 +00:00
|
|
|
pos = target + delta
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
look_at_from_pos(pos, target, up)
|
2014-10-03 03:10:51 +00:00
|
|
|
|
2015-11-21 12:31:25 +00:00
|
|
|
# Turn a little up or down
|
2014-10-03 03:10:51 +00:00
|
|
|
var t = get_transform()
|
2015-12-09 07:38:23 +00:00
|
|
|
t.basis = Matrix3(t.basis[0], deg2rad(angle_v_adjust))*t.basis
|
2014-10-03 03:10:51 +00:00
|
|
|
set_transform(t)
|
|
|
|
|
|
|
|
|
2015-12-09 07:38:23 +00:00
|
|
|
func _ready():
|
2015-11-21 12:31:25 +00:00
|
|
|
# Find collision exceptions for ray
|
2014-10-03 03:10:51 +00:00
|
|
|
var node = self
|
|
|
|
while(node):
|
|
|
|
if (node extends RigidBody):
|
|
|
|
collision_exception.append(node.get_rid())
|
|
|
|
break
|
|
|
|
else:
|
2015-12-09 07:38:23 +00:00
|
|
|
node = node.get_parent()
|
2014-10-03 03:10:51 +00:00
|
|
|
set_fixed_process(true)
|
2015-11-21 12:31:25 +00:00
|
|
|
# This detaches the camera transform from the parent spatial node
|
2014-10-03 03:10:51 +00:00
|
|
|
set_as_toplevel(true)
|