Compare commits

...
2 Commits
3 changed files with 32 additions and 18 deletions
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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:
+25 -11
View File
@@ -58,6 +58,9 @@ 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
var _swap_pitch: float = 0.0
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 +89,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)
@@ -112,6 +117,12 @@ func _process(_delta: float) -> void:
# Add a slight backward kick along the local Z axis # Add a slight backward kick along the local Z axis
vm_camera.translate_object_local(Vector3(0, 0, _recoil_pitch * 0.01)) vm_camera.translate_object_local(Vector3(0, 0, _recoil_pitch * 0.01))
# Swap Animation
_swap_pitch = lerpf(_swap_pitch, 0.0, 15.0 * _delta)
if _swap_pitch > 0.1:
vm_camera.rotate_object_local(Vector3.RIGHT, deg_to_rad(_swap_pitch))
vm_camera.translate_object_local(Vector3(0, -_swap_pitch * 0.005, 0))
vm_camera.fov = lerpf(vm_camera.fov, target_fov, 10.0 * _delta) vm_camera.fov = lerpf(vm_camera.fov, target_fov, 10.0 * _delta)
func _build_loadout() -> void: func _build_loadout() -> void:
@@ -265,6 +276,9 @@ func _equip_slot(slot: int) -> void:
if w.has_method("unequip"): if w.has_method("unequip"):
w.unequip() w.unequip()
if active_slot != slot:
_swap_pitch = 60.0
active_slot = slot active_slot = slot
if weapons.has(active_slot): if weapons.has(active_slot):