mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-16 08:55:33 +00:00
♻️ enhance readability, lerp both first and third person rotations, and set initial camera rotation to improve accuracy in relative motion derivation
This commit is contained in:
parent
8f94ae2a0f
commit
fae82c45f8
3 changed files with 56 additions and 39 deletions
|
|
@ -17,7 +17,7 @@ class_name PlayerInputController extends Node
|
||||||
@export var jetting:bool = false
|
@export var jetting:bool = false
|
||||||
@export var skiing:bool = false
|
@export var skiing:bool = false
|
||||||
@export var direction:Vector2
|
@export var direction:Vector2
|
||||||
@export var camera_rotation:Vector2
|
@export var camera_rotation:Vector3
|
||||||
|
|
||||||
signal jump
|
signal jump
|
||||||
signal primary(pressed: bool)
|
signal primary(pressed: bool)
|
||||||
|
|
|
||||||
|
|
@ -133,8 +133,8 @@ func _ready() -> void:
|
||||||
func(_source: Node, target: Node, amount: int) -> void:
|
func(_source: Node, target: Node, amount: int) -> void:
|
||||||
target.health.damage(amount, 0))
|
target.health.damage(amount, 0))
|
||||||
|
|
||||||
input.camera_rotation.x = rotation.x
|
# sets initial camera rotation to match global rotation of player
|
||||||
input.camera_rotation.y = rotation.y
|
input.camera_rotation = global_rotation
|
||||||
|
|
||||||
if _is_pawn():
|
if _is_pawn():
|
||||||
pawn_player = self
|
pawn_player = self
|
||||||
|
|
@ -161,31 +161,28 @@ func _ready() -> void:
|
||||||
%Inventory.hide()
|
%Inventory.hide()
|
||||||
hud.hide()
|
hud.hide()
|
||||||
|
|
||||||
|
input.camera_rotation = pivot.rotation
|
||||||
|
|
||||||
func _process(_delta:float) -> void:
|
func _process(_delta:float) -> void:
|
||||||
if not _is_pawn():
|
if not is_alive():
|
||||||
|
return
|
||||||
|
|
||||||
|
if _is_pawn():
|
||||||
|
# handle pivot rotation
|
||||||
|
pivot.rotation.x = lerp_angle(pivot.rotation.x, input.camera_rotation.x, .5)
|
||||||
|
pivot.rotation.y = lerp_angle(pivot.rotation.y, input.camera_rotation.y, .5)
|
||||||
|
# handle throw force display
|
||||||
|
if hud.throw_progress.is_visible_in_tree():
|
||||||
|
var time_elapsed: float = throw_duration_max - throw_timer.time_left
|
||||||
|
hud.throw_progress.set_value(time_elapsed / throw_duration_max * 100)
|
||||||
|
else:
|
||||||
if Game.type is Multiplayer and Game.type.mode == Multiplayer.Mode.FREE_FOR_ALL:
|
if Game.type is Multiplayer and Game.type.mode == Multiplayer.Mode.FREE_FOR_ALL:
|
||||||
iff.fill = Color.RED
|
iff.fill = Color.RED
|
||||||
elif is_instance_valid(pawn_player) and team_id:
|
elif is_instance_valid(pawn_player) and team_id:
|
||||||
iff.fill = Color.GREEN if team_id == pawn_player.team_id else Color.RED
|
iff.fill = Color.GREEN if team_id == pawn_player.team_id else Color.RED
|
||||||
_update_third_person_animations()
|
_update_third_person_animations()
|
||||||
|
# handle third person mesh rotation
|
||||||
if not is_alive():
|
tp_mesh.rotation.y = lerp_angle(tp_mesh.rotation.y, input.camera_rotation.y + PI, .6)
|
||||||
return
|
|
||||||
|
|
||||||
# compute target rotation from input.camera_rotation
|
|
||||||
var target_euler := Vector3(input.camera_rotation.x, input.camera_rotation.y, 0.0)
|
|
||||||
# smoothly interpolate rotation of pivot node towards target rotation
|
|
||||||
pivot.global_transform.basis = pivot.global_transform.basis.slerp(Basis.from_euler(target_euler), .6)
|
|
||||||
|
|
||||||
if not _is_pawn():
|
|
||||||
# compute target rotation from input.camera_rotation
|
|
||||||
var tp_target_euler := Vector3(.0, input.camera_rotation.y + PI, 0.0)
|
|
||||||
# smoothly interpolate rotation of third person node towards target rotation
|
|
||||||
tp_mesh.global_transform.basis = tp_mesh.global_transform.basis.slerp(Basis.from_euler(tp_target_euler), .6)
|
|
||||||
else:
|
|
||||||
if hud.throw_progress.is_visible_in_tree():
|
|
||||||
var time_elapsed: float = throw_duration_max - throw_timer.time_left
|
|
||||||
hud.throw_progress.set_value(time_elapsed / throw_duration_max * 100)
|
|
||||||
|
|
||||||
func _physics_process(delta:float) -> void:
|
func _physics_process(delta:float) -> void:
|
||||||
_update_jetpack_energy(delta)
|
_update_jetpack_energy(delta)
|
||||||
|
|
@ -271,25 +268,24 @@ func _integrate_forces(_state:PhysicsDirectBodyState3D) -> void:
|
||||||
# skip if player is dead
|
# skip if player is dead
|
||||||
if not is_alive():
|
if not is_alive():
|
||||||
return
|
return
|
||||||
# compute direction in local space
|
|
||||||
var _direction:Vector3 = (transform.basis * Vector3(
|
|
||||||
input.direction.x, 0, input.direction.y)).normalized()
|
|
||||||
|
|
||||||
# adjust direction based on pivot rotation
|
var world_direction := Vector3(input.direction.x, 0.0, input.direction.y)
|
||||||
_direction = _direction.rotated(Vector3.UP, pivot.rotation.y)
|
var view_direction := camera.global_transform.basis * world_direction
|
||||||
|
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
if not _direction.is_zero_approx() and not input.skiing:
|
|
||||||
# retrieve collision normal
|
# retrieve collision normal
|
||||||
var normal:Vector3 = walkable_surface_sensor.get_collision_normal(0)
|
var normal:Vector3 = walkable_surface_sensor.get_collision_normal(0)
|
||||||
|
|
||||||
|
if not view_direction.is_zero_approx() and not input.skiing:
|
||||||
# calculate the angle between the ground normal and the up vector
|
# calculate the angle between the ground normal and the up vector
|
||||||
var slope_angle:float = rad_to_deg(acos(normal.dot(Vector3.UP)))
|
var slope_angle:float = rad_to_deg(acos(normal.dot(Vector3.UP)))
|
||||||
# check if the slope angle exceeds the maximum slope angle
|
# check if the slope angle exceeds the maximum slope angle
|
||||||
if slope_angle <= max_floor_angle:
|
if slope_angle <= max_floor_angle:
|
||||||
# adjust direction based on the floor normal to align with the slope
|
# adjust direction based on the floor normal to align with the slope
|
||||||
_direction = _direction.slide(normal)
|
view_direction = view_direction.slide(normal)
|
||||||
|
|
||||||
linear_velocity = lerp(linear_velocity, _direction * ground_speed, .1)
|
linear_velocity = lerp(linear_velocity, view_direction * ground_speed, .1)
|
||||||
|
|
||||||
if _jumping:
|
if _jumping:
|
||||||
var v:float = sqrt(2. * g * jump_height)
|
var v:float = sqrt(2. * g * jump_height)
|
||||||
|
|
@ -297,8 +293,8 @@ func _integrate_forces(_state:PhysicsDirectBodyState3D) -> void:
|
||||||
|
|
||||||
_jumping = false
|
_jumping = false
|
||||||
|
|
||||||
_handle_aerial_control(_direction)
|
_handle_aerial_control(view_direction)
|
||||||
_handle_jetpack(_direction)
|
_handle_jetpack(view_direction)
|
||||||
_handle_ski()
|
_handle_ski()
|
||||||
|
|
||||||
func _update_third_person_animations() -> void:
|
func _update_third_person_animations() -> void:
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,7 @@ fov = 90.0
|
||||||
|
|
||||||
[node name="Inventory" type="Node3D" parent="Pivot"]
|
[node name="Inventory" type="Node3D" parent="Pivot"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 0.15, -0.2, -0.45)
|
transform = Transform3D(-1, 0, 1.50996e-07, 0, 1, 0, -1.50996e-07, 0, -1, 0.15, -0.2, -0.45)
|
||||||
script = ExtResource("6_du54c")
|
script = ExtResource("6_du54c")
|
||||||
|
|
||||||
[node name="SpaceGun" parent="Pivot/Inventory" instance=ExtResource("9_achlo")]
|
[node name="SpaceGun" parent="Pivot/Inventory" instance=ExtResource("9_achlo")]
|
||||||
|
|
@ -320,7 +320,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
visible = false
|
visible = false
|
||||||
|
|
||||||
[node name="Mesh" parent="ThirdPerson" node_paths=PackedStringArray("spine_ik_target_attachment") instance=ExtResource("8_eiy7q")]
|
[node name="Mesh" parent="ThirdPerson" node_paths=PackedStringArray("spine_ik_target_attachment") instance=ExtResource("8_eiy7q")]
|
||||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
transform = Transform3D(-1, 0, -1.50996e-07, 0, 1, 0, 1.50996e-07, 0, -1, 0, 0, 0)
|
||||||
spine_ik_target_attachment = NodePath("../../Pivot/SpineIKTarget")
|
spine_ik_target_attachment = NodePath("../../Pivot/SpineIKTarget")
|
||||||
|
|
||||||
[node name="Skeleton3D" parent="ThirdPerson/Mesh/Node" index="0"]
|
[node name="Skeleton3D" parent="ThirdPerson/Mesh/Node" index="0"]
|
||||||
|
|
@ -400,20 +400,32 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.6068e-14, -1.19209e-07, 9.5
|
||||||
[node name="sides" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun/Mesh/Armature/Skeleton3D/sides" index="0"]
|
[node name="sides" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun/Mesh/Armature/Skeleton3D/sides" index="0"]
|
||||||
layers = 2
|
layers = 2
|
||||||
|
|
||||||
|
[node name="BarrelsInner" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D" index="0"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
|
||||||
|
|
||||||
[node name="BarrelsInner" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/BarrelsInner" index="0"]
|
[node name="BarrelsInner" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/BarrelsInner" index="0"]
|
||||||
layers = 2
|
layers = 2
|
||||||
|
|
||||||
|
[node name="BarrelsOuter" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D" index="1"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
|
||||||
|
|
||||||
[node name="BarrelsOuter" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/BarrelsOuter" index="0"]
|
[node name="BarrelsOuter" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/BarrelsOuter" index="0"]
|
||||||
layers = 2
|
layers = 2
|
||||||
|
|
||||||
|
[node name="Base" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D" index="2"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
|
||||||
|
|
||||||
[node name="Base" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/Base" index="0"]
|
[node name="Base" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/Base" index="0"]
|
||||||
layers = 2
|
layers = 2
|
||||||
|
|
||||||
|
[node name="Grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D" index="3"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
|
||||||
|
|
||||||
[node name="Grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/Grip" index="0"]
|
[node name="Grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun/Armature/Skeleton3D/Grip" index="0"]
|
||||||
layers = 2
|
layers = 2
|
||||||
|
|
||||||
[node name="Barrels" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun" index="2"]
|
[node name="Barrels" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun" index="2"]
|
||||||
transform = Transform3D(-1, -7.45058e-09, 8.98726e-08, 8.42847e-08, 0, 1, 0, 1, 0, 1.19209e-07, 4.76837e-07, -0.55315)
|
transform = Transform3D(-1, 0, 8.42847e-08, 8.3819e-08, 0, 1, 0, 1, -3.72529e-09, -1.19209e-07, -4.76837e-07, -0.55315)
|
||||||
|
|
||||||
[node name="Skeleton3D" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature" index="0"]
|
[node name="Skeleton3D" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature" index="0"]
|
||||||
bones/0/rotation = Quaternion(0, 0.707107, 0.707107, 0)
|
bones/0/rotation = Quaternion(0, 0.707107, 0.707107, 0)
|
||||||
|
|
@ -421,12 +433,21 @@ bones/1/rotation = Quaternion(0, 0.707107, 0.707107, 0)
|
||||||
bones/2/rotation = Quaternion(0, 0.707107, 0.707107, 0)
|
bones/2/rotation = Quaternion(0, 0.707107, 0.707107, 0)
|
||||||
bones/3/rotation = Quaternion(0, 0.707107, 0.707107, 0)
|
bones/3/rotation = Quaternion(0, 0.707107, 0.707107, 0)
|
||||||
|
|
||||||
|
[node name="barrel" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D" index="0"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.19209e-07, 0)
|
||||||
|
|
||||||
[node name="barrel" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/barrel" index="0"]
|
[node name="barrel" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/barrel" index="0"]
|
||||||
layers = 2
|
layers = 2
|
||||||
|
|
||||||
|
[node name="grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D" index="1"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.082471, -0.0653242)
|
||||||
|
|
||||||
[node name="grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/grip" index="0"]
|
[node name="grip" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/grip" index="0"]
|
||||||
layers = 2
|
layers = 2
|
||||||
|
|
||||||
|
[node name="main" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D" index="2"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.19209e-07, 0)
|
||||||
|
|
||||||
[node name="main" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/main" index="0"]
|
[node name="main" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature/Skeleton3D/main" index="0"]
|
||||||
layers = 2
|
layers = 2
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue