blob: e52e1254044a82a0faca9e81f4d141d9d2c69ea3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
extends Spatial
var direction = Vector3.FORWARD
var tx: int
var was_target
func _physics_process(delta):
var vel = get_parent().get_linear_velocity()
var target = get_parent().target
if target:
var target_pos = target.get_global_transform().origin
look_at(target_pos, Vector3.UP)
rotate_object_local(Vector3(0, 1, 0), PI)
rotation.x = clamp(rotation.x, 0, rotation.x)
if not was_target:
pass
else:
vel.y = 0
if abs(vel.x) > 1.0 or abs(vel.z) > 1.0:
direction = lerp(direction, -vel.normalized(), 0.5 * delta)
global_transform.basis = get_rotation_from_direction(direction)
was_target = target
func get_rotation_from_direction(dir: Vector3) -> Basis:
dir = dir.normalized()
var x_axis = dir.cross(Vector3.UP)
return Basis(x_axis, Vector3.UP, -dir)
func _ready():
$ClippedCamera.add_exception(get_parent())
|