feat: implement foundational weapon systems, including hitscan and projectile base classes, reload mechanics, and player movement/camera integration.
This commit is contained in:
@@ -55,6 +55,14 @@ func _setup_viewmodel_viewport() -> void:
|
||||
dir_light.light_energy = 0.5
|
||||
add_child(dir_light)
|
||||
|
||||
var _bob_timer: float = 0.0
|
||||
var _recoil_pitch: float = 0.0
|
||||
var _recoil_yaw: float = 0.0
|
||||
|
||||
func add_recoil(pitch: float, yaw: float) -> void:
|
||||
_recoil_pitch += pitch * 20.0 # Scale up for visual model recoil
|
||||
_recoil_yaw += yaw * 20.0
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if is_instance_valid(vm_camera) and is_instance_valid(camera):
|
||||
vm_camera.global_transform = camera.global_transform
|
||||
@@ -68,6 +76,41 @@ func _process(_delta: float) -> void:
|
||||
else:
|
||||
var over_speed_factor = clampf((hspeed - 11.0) / 19.0, 0.0, 1.0) # maxes out at 30 m/s
|
||||
target_fov = lerpf(72.0, 80.0, over_speed_factor)
|
||||
|
||||
# Weapon Viewmodel Bobbing and Drift
|
||||
if player.is_on_floor() and hspeed > 1.0:
|
||||
# Scale bobbing frequency by walk speed (assuming base walk speed is ~10-11)
|
||||
_bob_timer += _delta * 12.0 * (hspeed / 11.0)
|
||||
var bob_y = sin(_bob_timer) * 0.015
|
||||
var bob_x = cos(_bob_timer * 0.5) * 0.01
|
||||
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))
|
||||
|
||||
# Visual Recoil
|
||||
_recoil_pitch = lerpf(_recoil_pitch, 0.0, 15.0 * _delta)
|
||||
_recoil_yaw = lerpf(_recoil_yaw, 0.0, 15.0 * _delta)
|
||||
|
||||
vm_camera.rotate_object_local(Vector3.RIGHT, deg_to_rad(_recoil_pitch))
|
||||
vm_camera.rotate_object_local(Vector3.UP, deg_to_rad(_recoil_yaw))
|
||||
# Add a slight backward kick along the local Z axis
|
||||
vm_camera.translate_object_local(Vector3(0, 0, _recoil_pitch * 0.01))
|
||||
|
||||
vm_camera.fov = lerpf(vm_camera.fov, target_fov, 10.0 * _delta)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user