-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoothing-alt.txt
55 lines (43 loc) · 2.03 KB
/
smoothing-alt.txt
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extends Node
export(NodePath) var _target
export(NodePath) var _angularSource
export(float) var effectMultiplier = 1.1
export(float) var translateEffectMultiplier = 1.0
export(float) var rotateEffectMultiplier = 1.0
export(float) var locationSmoothing = 0.2
export(float) var angularSmoothing = 0.2
onready var angularSource = get_node(_angularSource)
onready var target = get_node(_target)
onready var baseOrigin = target.transform.origin
var trailingVal = Vector3(0,0,0)
onready var baseOrientation = target.global_transform.basis
var targetVal = Vector3(0,0,0)
var trailingBasisX = Vector3(0,0,0)
var trailingBasisY = Vector3(0,0,0)
var trailingBasisZ = Vector3(0,0,0)
onready var lastRecSourceBasis = angularSource.global_transform.basis
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _basis_subtract(a, b):
return Basis(a.x - b.x, a.y - b.y, a.z - b.z)
func _process(delta):
if(angularSource != null):
var currentRecSourceBasis = angularSource.global_transform.basis
var targetBasisX = currentRecSourceBasis.x - lastRecSourceBasis.x
var targetBasisY = currentRecSourceBasis.y - lastRecSourceBasis.y
var targetBasisZ = currentRecSourceBasis.z - lastRecSourceBasis.z
trailingBasisX += (targetBasisX - trailingBasisX) / angularSmoothing * delta
trailingBasisY += (targetBasisY - trailingBasisY) / angularSmoothing * delta
trailingBasisZ += (targetBasisZ - trailingBasisZ) / angularSmoothing * delta
target.global_transform.basis = _basis_subtract(baseOrientation, Basis(trailingBasisX, trailingBasisY, trailingBasisZ))
trailingVal += (targetVal - trailingVal) / locationSmoothing * delta
var parent = target
var add = parent.global_transform.basis.xform_inv(trailingVal) * (effectMultiplier - 1) * (translateEffectMultiplier - 1)
target.transform.origin = baseOrigin - add
print(add)
func _on_ent_player_velocityChanged(velocity):
targetVal = Vector3(-velocity.x, velocity.y, -velocity.z)