feat: implement base weapon system classes for hitscan and projectile mechanics

This commit is contained in:
DottsGit
2026-06-09 22:40:52 -04:00
parent f63187e493
commit 3e6eb40add
3 changed files with 22 additions and 18 deletions
+20 -16
View File
@@ -58,6 +58,8 @@ func _setup_viewmodel_viewport() -> void:
var _bob_timer: float = 0.0
var _recoil_pitch: 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:
_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))
else:
_bob_timer = 0.0
if not player.is_on_floor():
# Airborne Drift
# Convert player velocity into camera's local space
var local_vel = camera.global_transform.basis.inverse() * player.velocity
# We want the weapon to lag behind movement.
# 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
drift_offset.x = clampf(drift_offset.x, -0.1, 0.1)
drift_offset.y = clampf(drift_offset.y, -0.1, 0.1)
vm_camera.translate_object_local(drift_offset)
# Slight rotation tilt as well
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))
if not player.is_on_floor():
# Airborne Drift
# Convert player velocity into camera's local space
var local_vel = camera.global_transform.basis.inverse() * player.velocity
_target_drift_offset = Vector3(local_vel.x * 0.01, local_vel.y * 0.01, 0)
# Clamp the drift
_target_drift_offset.x = clampf(_target_drift_offset.x, -0.1, 0.1)
_target_drift_offset.y = clampf(_target_drift_offset.y, -0.1, 0.1)
else:
_target_drift_offset = Vector3.ZERO
# 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
_recoil_pitch = lerpf(_recoil_pitch, 0.0, 15.0 * _delta)