Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c512870f2 | ||
|
|
3dc7fda622 | ||
|
|
18ab9da4a3 | ||
|
|
da4a6442c7 |
@@ -14,6 +14,7 @@ var _target_tilt: float = 0.0
|
||||
var _current_tilt: float = 0.0
|
||||
var _target_fov: float = 90.0
|
||||
var _weapon_fov_override: float = -1.0
|
||||
var _step_offset_y: float = 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -80,6 +81,10 @@ func _process(delta: float) -> void:
|
||||
camera.position.y = lerp(camera.position.y, 0.0, 0.15)
|
||||
camera.position.x = lerp(camera.position.x, 0.0, 0.15)
|
||||
|
||||
# ── Step Smoothing ─────────────────────────────────────────────────────
|
||||
_step_offset_y = lerpf(_step_offset_y, 0.0, 15.0 * delta)
|
||||
camera.position.y += _step_offset_y
|
||||
|
||||
# ── Wall-run tilt ─────────────────────────────────────────────────────
|
||||
_current_tilt = lerpf(_current_tilt, _target_tilt, 1.0 - exp(-params.wall_run_tilt_speed * delta))
|
||||
camera.rotation.z = deg_to_rad(_current_tilt)
|
||||
@@ -99,3 +104,9 @@ func set_weapon_fov(fov: float) -> void:
|
||||
## Called to reset tilt (e.g., on landing).
|
||||
func clear_wall_tilt() -> void:
|
||||
_target_tilt = 0.0
|
||||
|
||||
## Adds an offset to the camera so that when the player physics body snaps up a step,
|
||||
## the camera interpolates smoothly instead of snapping.
|
||||
func add_step_offset(offset_y: float) -> void:
|
||||
_step_offset_y += offset_y
|
||||
|
||||
|
||||
@@ -47,12 +47,12 @@ class_name MovementParams
|
||||
@export var wall_angle_threshold: float = 70.0
|
||||
@export var wall_detect_distance: float = 0.7
|
||||
@export var wall_ray_up_height: float = 0.6
|
||||
@export var wall_ray_down_height: float = -0.3
|
||||
@export var wall_ray_down_height: float = 0.0
|
||||
|
||||
# ── Wall Climb ────────────────────────────────────────────────────────────────
|
||||
@export var wall_climb_speed: float = 6.0
|
||||
@export var wall_climb_duration: float = 3.0
|
||||
@export var wall_climb_max_angle: float = 55.0
|
||||
@export var wall_climb_max_angle: float = 75.0
|
||||
@export var wall_climb_vault_forward: float = 16.0
|
||||
@export var wall_climb_vault_up: float = 14.0
|
||||
@export var wall_climb_vault_height_check: float = 1.0
|
||||
|
||||
@@ -46,6 +46,7 @@ var original_capsule_height: float = 1.8
|
||||
var slide_cooldown_timer: float = 0.0 # Prevents instant slide re-entry
|
||||
var wall_cooldown_timer: float = 0.0 # Prevents instant re-attachment after wall jump
|
||||
var is_crouched: bool = false
|
||||
var can_wall_climb: bool = true
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -260,21 +261,15 @@ func detect_wall_forward() -> Dictionary:
|
||||
if not player:
|
||||
return {"hit": false, "normal": Vector3.ZERO, "is_short": false}
|
||||
|
||||
var hvel := Vector3(player.velocity.x, 0.0, player.velocity.z)
|
||||
var move_dir := Vector3.ZERO
|
||||
if hvel.length_squared() > 0.1:
|
||||
move_dir = hvel.normalized()
|
||||
var move_dir := -player.global_transform.basis.z
|
||||
move_dir.y = 0.0
|
||||
if move_dir.length_squared() > 0.01:
|
||||
move_dir = move_dir.normalized()
|
||||
else:
|
||||
move_dir = -player.global_transform.basis.z
|
||||
move_dir.y = 0.0
|
||||
if move_dir.length_squared() > 0.01:
|
||||
move_dir = move_dir.normalized()
|
||||
|
||||
if move_dir.length_squared() < 0.1:
|
||||
return {"hit": false, "normal": Vector3.ZERO, "is_short": false}
|
||||
|
||||
var space_state := player.get_world_3d().direct_space_state
|
||||
var dist := params.wall_detect_distance
|
||||
var dist := 1.2 # Increased to reliably detect walls at an angle
|
||||
|
||||
# Lower ray (feet/knees)
|
||||
var origin_low := player.global_position + Vector3.UP * params.wall_ray_down_height
|
||||
|
||||
@@ -101,7 +101,7 @@ func update(delta: float) -> void:
|
||||
return
|
||||
|
||||
# ── Wall interaction (Run, Climb, Vault) ──────────────────────────────
|
||||
if machine.input_dir.length() > 0.1 and machine.wall_cooldown_timer <= 0.0:
|
||||
if machine.input_dir.length() > 0.1 and machine.input_dir.y <= 0.0 and machine.wall_cooldown_timer <= 0.0:
|
||||
var fwd_wall = machine.detect_wall_forward()
|
||||
if fwd_wall.hit:
|
||||
if fwd_wall.is_short:
|
||||
@@ -132,7 +132,7 @@ func update(delta: float) -> void:
|
||||
var looking_towards := look_dir.dot(-fwd_wall.normal) > 0.0
|
||||
var moving_towards := wish_dir.dot(-fwd_wall.normal) > cos(deg_to_rad(params.wall_climb_max_angle))
|
||||
|
||||
if looking_towards and moving_towards:
|
||||
if looking_towards and moving_towards and machine.can_wall_climb:
|
||||
machine.wall_normal = fwd_wall.normal
|
||||
machine.switch_to("wall_climb")
|
||||
return
|
||||
@@ -140,8 +140,14 @@ func update(delta: float) -> void:
|
||||
# Fallback to wall run
|
||||
var wall_n := machine.detect_wall_horizontal()
|
||||
if wall_n != Vector3.ZERO:
|
||||
machine.switch_to("wall_run")
|
||||
return
|
||||
var w_look_dir := -player.global_transform.basis.z
|
||||
var h_look := Vector3(w_look_dir.x, 0.0, w_look_dir.z).normalized()
|
||||
|
||||
# Require looking mostly along the wall (angle > 41 degrees from normal)
|
||||
# and inputting mostly along the wall (angle > 31 degrees from normal, allows W+A/D diagonally into wall)
|
||||
if absf(h_look.dot(wall_n)) < 0.75 and absf(wish_dir.dot(wall_n)) < 0.85:
|
||||
machine.switch_to("wall_run")
|
||||
return
|
||||
|
||||
# ── Dash ──────────────────────────────────────────────────────────────
|
||||
if machine.input_dash:
|
||||
|
||||
@@ -10,6 +10,7 @@ var _footstep_timer: float = 0.0
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
machine.on_ground = true
|
||||
machine.current_jump_count = 0
|
||||
machine.can_wall_climb = true
|
||||
# Clear wall tilt on landing
|
||||
var rig = _get_camera_rig()
|
||||
if rig:
|
||||
@@ -96,13 +97,13 @@ func update(delta: float) -> void:
|
||||
for i in range(player.get_slide_collision_count()):
|
||||
var col = player.get_slide_collision(i)
|
||||
if absf(col.get_normal().y) < 0.3: # Hit a wall
|
||||
var max_step_height = 0.5
|
||||
var max_step_height = 0.95
|
||||
var space_state = player.get_world_3d().direct_space_state
|
||||
var feet_y = player.global_position.y - (machine.original_capsule_height / 2.0)
|
||||
|
||||
# Raycast down from above the step
|
||||
var fwd = wish_dir.normalized()
|
||||
var ray_start = player.global_position + fwd * 0.5
|
||||
var ray_start = player.global_position + fwd * 0.65
|
||||
ray_start.y = feet_y + max_step_height + 0.1
|
||||
var ray_end = ray_start - Vector3.UP * (max_step_height + 0.2)
|
||||
|
||||
@@ -121,14 +122,20 @@ func update(delta: float) -> void:
|
||||
head_ray.exclude = [player.get_rid()]
|
||||
|
||||
if space_state.intersect_ray(head_ray).is_empty():
|
||||
# We can safely step up
|
||||
player.global_position.y += step_height + 0.01
|
||||
# Push slightly forward to get onto the step
|
||||
player.global_position += fwd * 0.1
|
||||
# Restore horizontal velocity that was lost from hitting the wall
|
||||
player.velocity.x = hvel.x
|
||||
player.velocity.z = hvel.z
|
||||
break
|
||||
# Check if there is enough space to move forward after stepping up
|
||||
var test_transform = player.global_transform
|
||||
test_transform.origin.y += step_height + 0.05
|
||||
if not player.test_move(test_transform, fwd * 0.15):
|
||||
# We can safely step up
|
||||
player.global_position.y += step_height + 0.01
|
||||
if player.head_pivot and player.head_pivot.has_method("add_step_offset"):
|
||||
player.head_pivot.add_step_offset(-(step_height + 0.01))
|
||||
# Push slightly forward to get onto the step
|
||||
player.global_position += fwd * 0.1
|
||||
# Restore horizontal velocity that was lost from hitting the wall
|
||||
player.velocity.x = hvel.x
|
||||
player.velocity.z = hvel.z
|
||||
break
|
||||
|
||||
_update_capsule_height()
|
||||
|
||||
@@ -156,7 +163,7 @@ func update(delta: float) -> void:
|
||||
return
|
||||
|
||||
# ── Wall interaction (Run, Climb, Vault) ──────────────────────────────
|
||||
if machine.input_dir.length() > 0.1 and machine.wall_cooldown_timer <= 0.0 and not machine.input_crouch:
|
||||
if machine.input_dir.length() > 0.1 and machine.input_dir.y <= 0.0 and machine.wall_cooldown_timer <= 0.0 and not machine.input_crouch:
|
||||
var fwd_wall = machine.detect_wall_forward()
|
||||
if fwd_wall.hit:
|
||||
if fwd_wall.is_short:
|
||||
@@ -188,7 +195,7 @@ func update(delta: float) -> void:
|
||||
var looking_towards := look_dir.dot(-fwd_wall.normal) > 0.0
|
||||
var moving_towards := wish_dir.dot(-fwd_wall.normal) > cos(deg_to_rad(params.wall_climb_max_angle))
|
||||
|
||||
if looking_towards and moving_towards:
|
||||
if looking_towards and moving_towards and machine.can_wall_climb:
|
||||
machine.wall_normal = fwd_wall.normal
|
||||
machine.switch_to("wall_climb")
|
||||
return
|
||||
@@ -197,8 +204,14 @@ func update(delta: float) -> void:
|
||||
var wall_n := machine.detect_wall_horizontal()
|
||||
if wall_n != Vector3.ZERO:
|
||||
if not player.is_on_floor():
|
||||
machine.switch_to("wall_run")
|
||||
return
|
||||
var w_look_dir := -player.global_transform.basis.z
|
||||
var h_look := Vector3(w_look_dir.x, 0.0, w_look_dir.z).normalized()
|
||||
|
||||
# Require looking mostly along the wall (angle > 41 degrees from normal)
|
||||
# and inputting mostly along the wall (angle > 31 degrees from normal, allows W+A/D diagonally into wall)
|
||||
if absf(h_look.dot(wall_n)) < 0.75 and absf(wish_dir.dot(wall_n)) < 0.85:
|
||||
machine.switch_to("wall_run")
|
||||
return
|
||||
|
||||
# ── Dash ──────────────────────────────────────────────────────────────
|
||||
if machine.input_dash:
|
||||
|
||||
@@ -93,6 +93,7 @@ func _detach() -> void:
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.wall_cooldown_timer = 0.3
|
||||
machine.can_wall_climb = false
|
||||
machine.switch_to("air")
|
||||
|
||||
func _vault() -> void:
|
||||
|
||||
@@ -56,6 +56,10 @@ func _setup_viewmodel_viewport() -> void:
|
||||
add_child(dir_light)
|
||||
|
||||
var _bob_timer: float = 0.0
|
||||
var _current_slide_tilt_z: float = 0.0
|
||||
var _current_slide_tilt_x: float = 0.0
|
||||
var _current_slide_offset_x: float = 0.0
|
||||
var _current_slide_offset_y: float = 0.0
|
||||
var _recoil_pitch: float = 0.0
|
||||
var _recoil_yaw: float = 0.0
|
||||
var _target_drift_offset: Vector3 = Vector3.ZERO
|
||||
@@ -80,15 +84,32 @@ func _process(_delta: float) -> void:
|
||||
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:
|
||||
# Weapon Viewmodel Bobbing, Drift, and Slide Tilt
|
||||
var is_sliding = player.has_method("get_node") and player.get_node_or_null("MovementStateMachine") and player.get_node("MovementStateMachine").current_state == "slide"
|
||||
|
||||
if is_sliding:
|
||||
_bob_timer = 0.0
|
||||
# Target tilt when sliding (inwards towards center, pitched slightly down)
|
||||
# Assuming weapon is on right side (standard FPS), tilting left (positive Z rotation)
|
||||
_current_slide_tilt_z = lerpf(_current_slide_tilt_z, deg_to_rad(15.0), 12.0 * _delta)
|
||||
_current_slide_tilt_x = lerpf(_current_slide_tilt_x, 0.0, 12.0 * _delta)
|
||||
# Move closer to center (negative X) and slightly down (negative Y)
|
||||
_current_slide_offset_x = lerpf(_current_slide_offset_x, -0.15, 12.0 * _delta)
|
||||
_current_slide_offset_y = lerpf(_current_slide_offset_y, -0.1, 12.0 * _delta)
|
||||
else:
|
||||
_current_slide_tilt_z = lerpf(_current_slide_tilt_z, 0.0, 10.0 * _delta)
|
||||
_current_slide_tilt_x = lerpf(_current_slide_tilt_x, 0.0, 10.0 * _delta)
|
||||
_current_slide_offset_x = lerpf(_current_slide_offset_x, 0.0, 10.0 * _delta)
|
||||
_current_slide_offset_y = lerpf(_current_slide_offset_y, 0.0, 10.0 * _delta)
|
||||
|
||||
if player.is_on_floor() and hspeed > 1.0:
|
||||
# Scale bobbing frequency by walk speed
|
||||
_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
|
||||
@@ -107,6 +128,12 @@ func _process(_delta: float) -> void:
|
||||
vm_camera.translate_object_local(_current_drift_offset)
|
||||
vm_camera.rotate_object_local(Vector3.UP, deg_to_rad(-_current_drift_offset.x * 30.0))
|
||||
vm_camera.rotate_object_local(Vector3.RIGHT, deg_to_rad(_current_drift_offset.y * 30.0))
|
||||
|
||||
# Apply slide tilt and offset
|
||||
if absf(_current_slide_tilt_z) > 0.001 or absf(_current_slide_offset_x) > 0.001:
|
||||
vm_camera.translate_object_local(Vector3(_current_slide_offset_x, _current_slide_offset_y, 0))
|
||||
vm_camera.rotate_object_local(Vector3.FORWARD, _current_slide_tilt_z)
|
||||
vm_camera.rotate_object_local(Vector3.RIGHT, _current_slide_tilt_x)
|
||||
|
||||
# Visual Recoil
|
||||
_recoil_pitch = lerpf(_recoil_pitch, 0.0, 15.0 * _delta)
|
||||
|
||||
Reference in New Issue
Block a user