Lerp framerate logic fixes

This commit is contained in:
Rob Kelly 2025-04-18 15:52:31 -06:00
parent 35cc441241
commit c74bfefe92
9 changed files with 63 additions and 19 deletions

View File

@ -9,12 +9,12 @@
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_eywuc"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_eywuc"]
[sub_resource type="Sky" id="Sky_pka60"] [sub_resource type="Sky" id="Sky_cr4pm"]
sky_material = SubResource("ProceduralSkyMaterial_eywuc") sky_material = SubResource("ProceduralSkyMaterial_eywuc")
[sub_resource type="Environment" id="Environment_nynr7"] [sub_resource type="Environment" id="Environment_nynr7"]
background_mode = 2 background_mode = 2
sky = SubResource("Sky_pka60") sky = SubResource("Sky_cr4pm")
[sub_resource type="PlaneMesh" id="PlaneMesh_b6st5"] [sub_resource type="PlaneMesh" id="PlaneMesh_b6st5"]
size = Vector2(50, 50) size = Vector2(50, 50)

View File

@ -0,0 +1,39 @@
[gd_scene load_steps=7 format=3 uid="uid://tpojpp5ua6u1"]
[ext_resource type="PackedScene" uid="uid://bwe2jdmvinhqd" path="res://src/player/player.tscn" id="1_qdhe6"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_hda7d"]
[sub_resource type="Sky" id="Sky_pka60"]
sky_material = SubResource("ProceduralSkyMaterial_hda7d")
[sub_resource type="Environment" id="Environment_nl4kk"]
background_mode = 2
sky = SubResource("Sky_pka60")
[sub_resource type="PlaneMesh" id="PlaneMesh_libd1"]
size = Vector2(50, 50)
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_5pddg"]
[node name="PlayerTest" type="Node3D"]
[node name="Player" parent="." instance=ExtResource("1_qdhe6")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.866025, -0.156955, -0.474726, 0.5, 0.271854, 0.82225, 0, -0.949453, 0.31391, 0, 0, 0)
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_nl4kk")
[node name="WorldFloor" type="StaticBody3D" parent="." groups=["PlasticMaterial"]]
collision_layer = 5
collision_mask = 0
[node name="MeshInstance3D" type="MeshInstance3D" parent="WorldFloor"]
mesh = SubResource("PlaneMesh_libd1")
skeleton = NodePath("../..")
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor"]
shape = SubResource("WorldBoundaryShape3D_5pddg")

View File

@ -73,7 +73,7 @@ folder_colors={
config/input/mouse_sensitivity_x=0.45 config/input/mouse_sensitivity_x=0.45
config/input/mouse_sensitivity_y=0.45 config/input/mouse_sensitivity_y=0.45
config/input/invert_pitch=false config/input/invert_pitch=false
config/input/mouse_acceleration=30.0 config/input/mouse_acceleration=42.0
audio/buses/override_bus_layout="user://audio_bus_layout.tres" audio/buses/override_bus_layout="user://audio_bus_layout.tres"
config/accessibility/enable_screen_shake=true config/accessibility/enable_screen_shake=true
config/accessibility/enable_head_bob=true config/accessibility/enable_head_bob=true

View File

@ -1,7 +1,7 @@
class_name Tool extends Node3D class_name Tool extends Node3D
## Abstract base class for spraygun types ## Abstract base class for spraygun types
const HUD_ACCEL := 36.0 @export var hud_accel := 50.0
var firing := false var firing := false
@ -36,6 +36,6 @@ func idle() -> void:
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if hud_tool: if hud_tool:
var weight := clampf(HUD_ACCEL * delta, 0.0, 1.0) var weight := 1 - exp(-hud_accel * delta)
hud_tool.global_basis = global_basis hud_tool.global_basis = global_basis
hud_tool.global_position = hud_tool.global_position.lerp(global_position, weight) hud_tool.global_position = hud_tool.global_position.lerp(global_position, weight)

View File

@ -43,7 +43,7 @@ func _idle() -> void:
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
hud_tool.global_basis = global_basis hud_tool.global_basis = global_basis
var weight := clampf(HUD_ACCEL * delta, 0.0, 1.0) var weight := 1 - exp(-hud_accel * delta)
var target_position := resting_position.global_position var target_position := resting_position.global_position
if raycast.is_colliding(): if raycast.is_colliding():
target_position = raycast.get_collision_point() target_position = raycast.get_collision_point()

View File

@ -35,9 +35,12 @@ func camera_motion(motion: Vector2) -> void:
) )
func _physics_process(_delta: float) -> void: func _physics_process(delta: float) -> void:
var mouse_accel: float = Game.settings.mouse_acceleration / 60.0 var mouse_accel: float = Game.settings.mouse_acceleration
if player.firing: if player.firing:
mouse_accel = FOCUS_ACCELERATION / 60.0 mouse_accel = FOCUS_ACCELERATION
rotation.y = lerp_angle(rotation.y, _target.y, mouse_accel)
rotation.x = lerp_angle(rotation.x, _target.x, mouse_accel) var weight := 1 - exp(-mouse_accel * delta)
#var weight := mouse_accel / 60.0
rotation.y = lerp_angle(rotation.y, _target.y, weight)
rotation.x = lerp_angle(rotation.x, _target.x, weight)

View File

@ -21,9 +21,10 @@ var timescale: float:
func _process(delta: float) -> void: func _process(delta: float) -> void:
var speed := player.velocity.length() var speed := player.velocity.length()
var weight := 1 - exp(-BLEND_ACCELERATION * delta)
if player.is_on_floor(): if player.is_on_floor():
var timescale_target := speed * VELOCITY_TIMESCALE_FACTOR var timescale_target := speed * VELOCITY_TIMESCALE_FACTOR
timescale = lerpf(timescale, timescale_target, BLEND_ACCELERATION * delta) timescale = lerpf(timescale, timescale_target, weight)
else: else:
timescale = 0.0 timescale = 0.0
@ -32,6 +33,6 @@ func _process(delta: float) -> void:
if player.is_on_floor(): if player.is_on_floor():
blend_target = speed * VELOCITY_BLEND_FACTOR blend_target = speed * VELOCITY_BLEND_FACTOR
blend = lerpf(blend, blend_target, BLEND_ACCELERATION * delta) blend = lerpf(blend, blend_target, weight)
else: else:
blend = 0.0 blend = 0.0

View File

@ -195,8 +195,9 @@ func _physics_process(delta: float) -> void:
# Friction # Friction
var friction := get_friction() var friction := get_friction()
velocity.x = lerpf(velocity.x, 0, friction) var weight := 1 - exp(-friction * 60 * delta)
velocity.z = lerpf(velocity.z, 0, friction) velocity.x = lerpf(velocity.x, 0, weight)
velocity.z = lerpf(velocity.z, 0, weight)
_was_on_floor = is_on_floor() _was_on_floor = is_on_floor()

View File

@ -215,10 +215,10 @@ anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
offset_left = -400.102 offset_left = -400.498
offset_top = -298.829 offset_top = -299.892
offset_right = -400.102 offset_right = -400.498
offset_bottom = -298.829 offset_bottom = -299.892
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
script = ExtResource("4_ud8na") script = ExtResource("4_ud8na")