attenuated headbob/tilt based on speed, now less sickening on tiny movements
This commit is contained in:
parent
7dd8f88ca7
commit
adde9f5c3c
@ -610,7 +610,7 @@ grow_vertical = 0
|
|||||||
alignment = 2
|
alignment = 2
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="HUD"]
|
[node name="Label" type="Label" parent="HUD"]
|
||||||
anchors_preset = -1
|
anchors_preset = 5
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
anchor_right = 0.5
|
anchor_right = 0.5
|
||||||
offset_left = -300.0
|
offset_left = -300.0
|
||||||
|
@ -6,32 +6,36 @@ class_name ViewMovement
|
|||||||
@export var head_bob_camera : Camera3D
|
@export var head_bob_camera : Camera3D
|
||||||
@export var head_bob_focus_raycast : RayCast3D
|
@export var head_bob_focus_raycast : RayCast3D
|
||||||
@export var enable_head_bob := true
|
@export var enable_head_bob := true
|
||||||
@export var head_bob_amplitude := 0.040
|
@export var head_bob_max_effect_velocity := 6.5
|
||||||
@export var head_bob_frequency := 0.015
|
@export var head_bob_amplitude := 0.06
|
||||||
|
@export var head_bob_frequency := 0.02
|
||||||
@export var target_stabilisation := false
|
@export var target_stabilisation := false
|
||||||
@export_category("Tilting")
|
@export_category("Tilting")
|
||||||
@export var enable_tilt := true
|
@export var enable_tilt := true
|
||||||
@export var tilt_amount := 0.02
|
@export var tilt_max_effect_velocity := 6.5
|
||||||
|
@export var tilt_amount_x := 0.03
|
||||||
|
@export var tilt_amount_y := 0.00
|
||||||
|
|
||||||
|
var lemniscate_sample_point = 0.0
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
var player_velocity = player.velocity.length()
|
||||||
if enable_head_bob:
|
if enable_head_bob:
|
||||||
check_motion(delta)
|
check_motion(delta, player_velocity)
|
||||||
if target_stabilisation:
|
if target_stabilisation:
|
||||||
head_bob_camera.look_at(focus_target())
|
head_bob_camera.look_at(focus_target())
|
||||||
if enable_tilt:
|
if enable_tilt:
|
||||||
tilt_cam(delta)
|
tilt_cam(delta, player_velocity)
|
||||||
|
|
||||||
|
|
||||||
func check_motion(delta) -> void:
|
func check_motion(delta, vel) -> void:
|
||||||
var speed = player.velocity.length_squared()
|
var amp = vel / head_bob_max_effect_velocity
|
||||||
if speed < 2.0:
|
|
||||||
reset_position(delta)
|
|
||||||
return
|
|
||||||
if !player.is_on_floor():
|
if !player.is_on_floor():
|
||||||
reset_position(delta)
|
reset_position(delta)
|
||||||
return
|
return
|
||||||
play_motion(sample_lemniscate(Time.get_ticks_msec() * head_bob_frequency), delta)
|
lemniscate_sample_point += (delta * 1000.0) * head_bob_frequency * amp
|
||||||
|
play_motion(sample_lemniscate(lemniscate_sample_point, vel), delta)
|
||||||
|
|
||||||
|
|
||||||
func reset_position(delta) -> void:
|
func reset_position(delta) -> void:
|
||||||
@ -39,10 +43,11 @@ func reset_position(delta) -> void:
|
|||||||
head_bob_camera.position = lerp(head_bob_camera.position, Vector3.ZERO, 7.0 * delta)
|
head_bob_camera.position = lerp(head_bob_camera.position, Vector3.ZERO, 7.0 * delta)
|
||||||
|
|
||||||
|
|
||||||
func sample_lemniscate(t: float) -> Vector2:
|
func sample_lemniscate(t: float, v: float) -> Vector2:
|
||||||
var pos := Vector2.ZERO
|
var pos := Vector2.ZERO
|
||||||
pos.y += sin(t) * head_bob_amplitude
|
var amp = head_bob_amplitude * (v / head_bob_max_effect_velocity)
|
||||||
pos.x += cos(t / 2.0) * head_bob_amplitude * 2.0
|
pos.y += sin(t) * amp
|
||||||
|
pos.x += cos(t / 2.0) * amp * 2.0
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
|
|
||||||
@ -58,11 +63,10 @@ func focus_target() -> Vector3:
|
|||||||
return head_bob_focus_raycast.global_position + -head_bob_focus_raycast.global_transform.basis.z * 15.0
|
return head_bob_focus_raycast.global_position + -head_bob_focus_raycast.global_transform.basis.z * 15.0
|
||||||
|
|
||||||
|
|
||||||
func tilt_cam(delta):
|
func tilt_cam(delta, vel):
|
||||||
if player.velocity.length() < 1.0:
|
|
||||||
return
|
|
||||||
var dot = player.velocity.normalized().dot(-global_transform.basis.z)
|
var dot = player.velocity.normalized().dot(-global_transform.basis.z)
|
||||||
dot = -abs(dot) + 1
|
dot = -abs(dot) + 1
|
||||||
|
dot *= vel / tilt_max_effect_velocity
|
||||||
var input_vector = Input.get_vector("Move Left", "Move Right", "Move Forward", "Move Backward")
|
var input_vector = Input.get_vector("Move Left", "Move Right", "Move Forward", "Move Backward")
|
||||||
head_bob_camera.rotation.z = lerp(head_bob_camera.rotation.z, tilt_amount * dot * -input_vector.x, 8.0 * delta)
|
head_bob_camera.rotation.z = lerp(head_bob_camera.rotation.z, tilt_amount_x * dot * -input_vector.x, 8.0 * delta)
|
||||||
#head_bob_camera.rotation.x = lerp(head_bob_camera.rotation.x, tilt_amount * dot * input_vector.y, 8.0 * delta)
|
head_bob_camera.rotation.x = lerp(head_bob_camera.rotation.x, tilt_amount_y * (1.0 - dot) * input_vector.y, 8.0 * delta)
|
||||||
|
@ -23,8 +23,8 @@ var enemy_names = []
|
|||||||
|
|
||||||
var wave_start_label_shrinking := false
|
var wave_start_label_shrinking := false
|
||||||
var wave_start_label_growing := false
|
var wave_start_label_growing := false
|
||||||
var wave_start_label_acceleration := 200.0
|
var wave_start_label_ease_time := 1.0
|
||||||
var wave_start_label_speed := 0.0
|
var wave_start_label_ease_progress := 0.0
|
||||||
|
|
||||||
|
|
||||||
func set_energy_visible(value):
|
func set_energy_visible(value):
|
||||||
@ -35,29 +35,30 @@ func set_offhand_energy_visible(value):
|
|||||||
offhand_energy_bar.set_visible(value)
|
offhand_energy_bar.set_visible(value)
|
||||||
|
|
||||||
|
|
||||||
|
func ease_in_out_quart(x : float) -> float:
|
||||||
|
return 8.0 * x * x * x * x if x < 0.5 else 1 - pow(-2.0 * x + 2.0, 4) / 2.0
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
fps_label.text = "FPS: " + str(Engine.get_frames_per_second())
|
fps_label.text = "FPS: " + str(Engine.get_frames_per_second())
|
||||||
|
|
||||||
wave_start_label.text = "Press [" + Data.player_keymap.ready.as_text_key_label() + "] to start wave"
|
wave_start_label.text = "Press [" + Data.player_keymap.ready.as_text_key_label() + "] to start wave"
|
||||||
if wave_start_label_growing:
|
if wave_start_label_growing or wave_start_label_shrinking:
|
||||||
wave_start_label.set_visible(true)
|
wave_start_label_ease_progress += delta
|
||||||
wave_start_label_speed += wave_start_label_acceleration * delta
|
if wave_start_label_growing:
|
||||||
wave_start_label.offset_left -= wave_start_label_speed * delta
|
wave_start_label.set_visible(true)
|
||||||
wave_start_label.offset_right += wave_start_label_speed * delta
|
wave_start_label.offset_left = lerp(0.0, -300.0, ease_in_out_quart(wave_start_label_ease_progress / wave_start_label_ease_time))
|
||||||
if wave_start_label.offset_left <= -300:
|
wave_start_label.offset_right = lerp(0.0, 300.0, ease_in_out_quart(wave_start_label_ease_progress / wave_start_label_ease_time))
|
||||||
wave_start_label.offset_left = -300
|
if wave_start_label_ease_progress >= wave_start_label_ease_time:
|
||||||
wave_start_label.offset_right = 300
|
wave_start_label_growing = false
|
||||||
wave_start_label_growing = false
|
wave_start_label_ease_progress = 0.0
|
||||||
wave_start_label_speed = 0.0
|
elif wave_start_label_shrinking:
|
||||||
if wave_start_label_shrinking:
|
wave_start_label.offset_left = lerp(-300.0, 0.0, ease_in_out_quart(wave_start_label_ease_progress / wave_start_label_ease_time))
|
||||||
wave_start_label_speed += wave_start_label_acceleration * delta
|
wave_start_label.offset_right = lerp(300.0, 0.0, ease_in_out_quart(wave_start_label_ease_progress / wave_start_label_ease_time))
|
||||||
wave_start_label.offset_left += wave_start_label_speed * delta
|
if wave_start_label_ease_progress >= wave_start_label_ease_time:
|
||||||
wave_start_label.offset_right -= wave_start_label_speed * delta
|
wave_start_label.set_visible(false)
|
||||||
if wave_start_label.offset_left >= 0:
|
wave_start_label_shrinking = false
|
||||||
wave_start_label.set_visible(false)
|
wave_start_label_ease_progress = 0.0
|
||||||
wave_start_label.offset_left = 0
|
|
||||||
wave_start_label.offset_right = 0
|
|
||||||
wave_start_label_shrinking = false
|
|
||||||
wave_start_label_speed = 0.0
|
|
||||||
|
|
||||||
|
|
||||||
func grow_wave_start_label():
|
func grow_wave_start_label():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user