Feat/12 add effects and better animations to fpv #17
@@ -47,7 +47,7 @@ func _process(delta: float) -> void:
|
|||||||
fire_cooldown -= delta
|
fire_cooldown -= delta
|
||||||
|
|
||||||
if reloading:
|
if reloading:
|
||||||
var spin_speed = PI * 4.0
|
var spin_speed = PI * 8.0
|
||||||
model_root.rotation.x += spin_speed * delta
|
model_root.rotation.x += spin_speed * delta
|
||||||
|
|
||||||
if reload_timer > 0.0:
|
if reload_timer > 0.0:
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func _process(delta: float) -> void:
|
|||||||
fire_cooldown -= delta
|
fire_cooldown -= delta
|
||||||
|
|
||||||
if reloading:
|
if reloading:
|
||||||
var spin_speed = PI * 4.0
|
var spin_speed = PI * 8.0
|
||||||
model_root.rotation.x += spin_speed * delta
|
model_root.rotation.x += spin_speed * delta
|
||||||
|
|
||||||
if reload_timer > 0.0:
|
if reload_timer > 0.0:
|
||||||
|
|||||||
+15
-11
@@ -58,6 +58,8 @@ func _setup_viewmodel_viewport() -> void:
|
|||||||
var _bob_timer: float = 0.0
|
var _bob_timer: float = 0.0
|
||||||
var _recoil_pitch: float = 0.0
|
var _recoil_pitch: float = 0.0
|
||||||
var _recoil_yaw: float = 0.0
|
var _recoil_yaw: float = 0.0
|
||||||
|
var _target_drift_offset: Vector3 = Vector3.ZERO
|
||||||
|
var _current_drift_offset: Vector3 = Vector3.ZERO
|
||||||
|
|
||||||
func add_recoil(pitch: float, yaw: float) -> void:
|
func add_recoil(pitch: float, yaw: float) -> void:
|
||||||
_recoil_pitch += pitch * 20.0 # Scale up for visual model recoil
|
_recoil_pitch += pitch * 20.0 # Scale up for visual model recoil
|
||||||
@@ -86,22 +88,24 @@ func _process(_delta: float) -> void:
|
|||||||
vm_camera.translate_object_local(Vector3(bob_x, bob_y, 0))
|
vm_camera.translate_object_local(Vector3(bob_x, bob_y, 0))
|
||||||
else:
|
else:
|
||||||
_bob_timer = 0.0
|
_bob_timer = 0.0
|
||||||
|
|
||||||
if not player.is_on_floor():
|
if not player.is_on_floor():
|
||||||
# Airborne Drift
|
# Airborne Drift
|
||||||
# Convert player velocity into camera's local space
|
# Convert player velocity into camera's local space
|
||||||
var local_vel = camera.global_transform.basis.inverse() * player.velocity
|
var local_vel = camera.global_transform.basis.inverse() * player.velocity
|
||||||
# We want the weapon to lag behind movement.
|
_target_drift_offset = Vector3(local_vel.x * 0.01, local_vel.y * 0.01, 0)
|
||||||
# If player moves left (-x), weapon should drift right (+x relative to camera, which means vm_camera shifts left -x to make weapon appear right)
|
|
||||||
# Wait, if vm_camera shifts left, the weapon (which is rendered by it) appears to shift RIGHT on the screen!
|
|
||||||
# So vm_camera shifts in the SAME direction as local velocity.
|
|
||||||
var drift_offset = Vector3(local_vel.x * 0.01, local_vel.y * 0.01, 0)
|
|
||||||
# Clamp the drift
|
# Clamp the drift
|
||||||
drift_offset.x = clampf(drift_offset.x, -0.1, 0.1)
|
_target_drift_offset.x = clampf(_target_drift_offset.x, -0.1, 0.1)
|
||||||
drift_offset.y = clampf(drift_offset.y, -0.1, 0.1)
|
_target_drift_offset.y = clampf(_target_drift_offset.y, -0.1, 0.1)
|
||||||
vm_camera.translate_object_local(drift_offset)
|
else:
|
||||||
# Slight rotation tilt as well
|
_target_drift_offset = Vector3.ZERO
|
||||||
vm_camera.rotate_object_local(Vector3.UP, deg_to_rad(-local_vel.x * 0.5))
|
|
||||||
vm_camera.rotate_object_local(Vector3.RIGHT, deg_to_rad(local_vel.y * 0.5))
|
# Smoothly apply drift so jumping/landing doesn't snap
|
||||||
|
_current_drift_offset = _current_drift_offset.lerp(_target_drift_offset, 15.0 * _delta)
|
||||||
|
|
||||||
|
vm_camera.translate_object_local(_current_drift_offset)
|
||||||
|
vm_camera.rotate_object_local(Vector3.UP, deg_to_rad(-_current_drift_offset.x * 50.0))
|
||||||
|
vm_camera.rotate_object_local(Vector3.RIGHT, deg_to_rad(_current_drift_offset.y * 50.0))
|
||||||
|
|
||||||
# Visual Recoil
|
# Visual Recoil
|
||||||
_recoil_pitch = lerpf(_recoil_pitch, 0.0, 15.0 * _delta)
|
_recoil_pitch = lerpf(_recoil_pitch, 0.0, 15.0 * _delta)
|
||||||
|
|||||||
Reference in New Issue
Block a user