AShadowWithoutLight/Camera.gd

67 lines
1.5 KiB
GDScript

extends Camera
# Depression
var downForceStrength = 0
#Mania
export var max_offset = 0.3 # Maximum hor/ver shake in pixels.
export var max_roll = 0.1 # Maximum rotation in radians (use sparingly).
#export (NodePath) var target # Assign the node this camera will follow.
var trauma = 0.0 # Current shake strength.
var trauma_power = 2 # Trauma exponent. Use [2, 3].
var downForce = false;
onready var noise = OpenSimplexNoise.new()
var noise_y = 0
var pivot
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
noise.seed = randi()
noise.period = 4
noise.octaves = 2
pivot = get_parent();
func changeShaking(setTrauma):
trauma = setTrauma
func changeDownForce(force):
downForceStrength = force
func _process(delta):
# if target:
# global_position = get_node(target).global_position
if trauma:
shake()
if downForceStrength<0:
if(pivot.rotation.x > -1.4):
#print(pivot.rotation.x)
pivot.rotate_x(downForceStrength)
func shake():
var amount = pow(trauma, trauma_power)
noise_y += 1
# Using noise
#rotation = max_roll * amount * noise.get_noise_2d(noise.seed, noise_y)
v_offset = max_offset * amount * noise.get_noise_2d(noise.seed*3, noise_y)
h_offset = max_offset * amount * noise.get_noise_2d(noise.seed*2, noise_y)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func reset():
trauma = 0
downForce=false
downForceStrength = 0;