mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-16 00:44:50 +00:00
Implement movement smoothing on Player entity
This commit is contained in:
parent
4abe6f8374
commit
01e25ccedf
11 changed files with 587 additions and 77 deletions
|
|
@ -42,17 +42,17 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
|
|||
@export var nickname : String
|
||||
|
||||
@onready var input : PlayerInput = $PlayerInput
|
||||
@onready var camera : Camera3D = $SpringArm3D/Camera3D
|
||||
@onready var camera : Camera3D = $Smoothing/SpringArm3D/Camera3D
|
||||
@onready var hud : CanvasLayer = $HUD
|
||||
@onready var shape_cast : ShapeCast3D = $ShapeCast3D
|
||||
@onready var weapon : Node3D = $SpringArm3D/Inventory/SpaceGun
|
||||
@onready var weapon : Node3D = $Smoothing/SpringArm3D/Inventory/SpaceGun
|
||||
@onready var animation_player : AnimationPlayer = $AnimationPlayer
|
||||
@onready var health_component : Area3D = $HealthComponent
|
||||
@onready var collision_shape : CollisionShape3D = $CollisionShape3D
|
||||
@onready var flag_carry_component : FlagCarryComponent = $FlagCarryComponent
|
||||
@onready var spring_arm_height : float = $SpringArm3D.position.y
|
||||
@onready var spring_arm_height : float = $Smoothing/SpringArm3D.position.y
|
||||
@onready var _original_weapon_transform : Transform3D = weapon.transform
|
||||
@onready var flag_carry_attachment : Node3D = $SpringArm3D/FlagCarryAttachment
|
||||
@onready var flag_carry_attachment : Node3D = $Smoothing/SpringArm3D/FlagCarryAttachment
|
||||
@onready var _game_settings : Settings = get_node("/root/GlobalSettings")
|
||||
|
||||
signal died(player : Player)
|
||||
|
|
@ -68,24 +68,25 @@ func _ready() -> void:
|
|||
health_component.health_changed.connect(iff._on_health_changed)
|
||||
health_component.health_changed.emit(health_component.health)
|
||||
health_component.health_zeroed.connect(die)
|
||||
|
||||
|
||||
input.fired_primary.connect(_fire_primary)
|
||||
input.jumped.connect(_jump)
|
||||
input.throwed_flag.connect(_throw_flag)
|
||||
|
||||
|
||||
input.MOUSE_SENSITIVITY = _game_settings.mouse_sensitivity
|
||||
input.inverted_y_axis = _game_settings.inverted_y_axis
|
||||
|
||||
|
||||
if _is_pawn():
|
||||
camera.current = true
|
||||
camera.fov = _game_settings.fov
|
||||
# set the spring arm translation to be about head height level
|
||||
$SpringArm3D.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
|
||||
$Smoothing/SpringArm3D.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
|
||||
flag_carry_attachment.hide()
|
||||
remove_child($ThirdPerson)
|
||||
|
||||
$Smoothing.remove_child($Smoothing/ThirdPerson)
|
||||
else:
|
||||
# set the iff attachment translation to be about head height level
|
||||
$ThirdPerson/IFFAttachment.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
|
||||
$Smoothing/ThirdPerson/IFFAttachment.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
|
||||
remove_child(hud)
|
||||
weapon.hide()
|
||||
|
||||
|
|
@ -128,13 +129,17 @@ func _handle_aerial_control(direction : Vector3) -> void:
|
|||
if not input.jetting and not is_on_floor():
|
||||
apply_force(direction * aerial_control_force)
|
||||
|
||||
func _handle_jetpack(delta : float, direction : Vector3) -> void:
|
||||
func _handle_jetpack(direction : Vector3) -> void:
|
||||
if input.jetting:
|
||||
if energy > 0:
|
||||
var up_vector : Vector3 = Vector3.UP * jetpack_vertical_force * jetpack_force_factor
|
||||
var side_vector : Vector3 = direction * jetpack_horizontal_force * jetpack_force_factor
|
||||
apply_force(up_vector + side_vector)
|
||||
energy -= energy_drain_rate * delta
|
||||
|
||||
func _update_jetpack_energy(delta : float) -> void:
|
||||
if input.jetting:
|
||||
if energy > 0:
|
||||
energy -= energy_drain_rate * delta
|
||||
else:
|
||||
energy += energy_charge_rate * delta
|
||||
|
||||
|
|
@ -148,7 +153,7 @@ func _process(_delta : float) -> void:
|
|||
else:
|
||||
iff.show()
|
||||
if not _is_pawn():
|
||||
$ThirdPerson/PlayerMesh.global_transform.basis = Basis.from_euler(Vector3(0.0, input.camera_rotation.x + PI, 0.0))
|
||||
$Smoothing/ThirdPerson/PlayerMesh.global_transform.basis = Basis.from_euler(Vector3(0.0, input.camera_rotation.x + PI, 0.0))
|
||||
else:
|
||||
if animation_player.current_animation == "shoot":
|
||||
pass
|
||||
|
|
@ -157,20 +162,24 @@ func _process(_delta : float) -> void:
|
|||
%SpringArm3D.global_transform.basis = Basis.from_euler(Vector3(input.camera_rotation.y, input.camera_rotation.x, 0.0))
|
||||
|
||||
func _physics_process(delta : float) -> void:
|
||||
_update_jetpack_energy(delta)
|
||||
|
||||
func _handle_movement() -> void:
|
||||
# retrieve user's direction vector
|
||||
var _input_dir : Vector2 = input.direction
|
||||
# compute direction in local space
|
||||
var _direction : Vector3 = (transform.basis * Vector3(_input_dir.x, 0, _input_dir.y)).normalized()
|
||||
|
||||
_update_third_person_animations()
|
||||
|
||||
if _is_player_dead():
|
||||
return
|
||||
|
||||
# adjust direction based on spring arm rotation
|
||||
_direction = _direction.rotated(Vector3.UP, $SpringArm3D.rotation.y)
|
||||
_direction = _direction.rotated(Vector3.UP, $Smoothing/SpringArm3D.rotation.y)
|
||||
|
||||
_handle_aerial_control(_direction)
|
||||
_handle_jetpack(delta, _direction)
|
||||
_handle_jetpack(_direction)
|
||||
|
||||
# handle ski
|
||||
if _is_skiing():
|
||||
|
|
@ -191,18 +200,20 @@ func _physics_process(delta : float) -> void:
|
|||
|
||||
linear_velocity = lerp(linear_velocity, _direction * ground_speed, .1)
|
||||
|
||||
func _integrate_forces(_state : PhysicsDirectBodyState3D) -> void:
|
||||
if is_on_floor() and _jumping:
|
||||
var v : float = sqrt(2 * g * jump_height)
|
||||
apply_central_impulse(Vector3(0, mass * v, 0))
|
||||
if _jumping:
|
||||
var v : float = sqrt(2 * g * jump_height)
|
||||
apply_central_impulse(Vector3(0, mass * v, 0))
|
||||
|
||||
_jumping = false
|
||||
|
||||
func _integrate_forces(_state : PhysicsDirectBodyState3D) -> void:
|
||||
_handle_movement()
|
||||
|
||||
func _update_third_person_animations() -> void:
|
||||
if _is_pawn():
|
||||
return
|
||||
|
||||
var tp_player : Vanguard = $ThirdPerson/PlayerMesh
|
||||
var tp_player : Vanguard = $Smoothing/ThirdPerson/PlayerMesh
|
||||
|
||||
if _is_player_dead():
|
||||
tp_player.set_ground_state(Vanguard.GroundState.GROUND_STATE_DEAD)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
[gd_scene load_steps=21 format=3 uid="uid://cbhx1xme0sb7k"]
|
||||
[gd_scene load_steps=22 format=3 uid="uid://cbhx1xme0sb7k"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"]
|
||||
[ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/assets/vanguard.tscn" id="2_beyex"]
|
||||
[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_vjqny"]
|
||||
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8co0qa2omjmh" path="res://entities/weapons/space_gun/space_gun.tscn" id="4_ehwwq"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8co0qa2omjmh" path="res://entities/weapons/space_gun/space_gun.tscn" id="4_6jh57"]
|
||||
[ext_resource type="PackedScene" uid="uid://dn1tcakam5egs" path="res://entities/weapons/space_gun/projectile.tscn" id="5_2xh36"]
|
||||
[ext_resource type="PackedScene" uid="uid://bof3mg7wgxrmn" path="res://components/health_component.tscn" id="5_t6i6e"]
|
||||
[ext_resource type="PackedScene" uid="uid://dn1tcakam5egs" path="res://entities/weapons/space_gun/projectile.tscn" id="5_w56pa"]
|
||||
[ext_resource type="Script" path="res://entities/player/player_input.gd" id="6_ymcrr"]
|
||||
[ext_resource type="PackedScene" uid="uid://dsysi2rd3bu76" path="res://interfaces/hud/iff.tscn" id="7_8hc80"]
|
||||
[ext_resource type="PackedScene" uid="uid://2t8ql8pkxv6c" path="res://components/flag_carry_component.tscn" id="7_e7s1a"]
|
||||
[ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="11_k330l"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
|
||||
resource_local_to_scene = true
|
||||
|
|
@ -27,7 +28,7 @@ length = 0.001
|
|||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/path = NodePath("Smoothing/SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
|
|
@ -39,7 +40,7 @@ tracks/0/keys = {
|
|||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/path = NodePath("Smoothing/SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
|
|
@ -51,7 +52,7 @@ tracks/1/keys = {
|
|||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("SpringArm3D:position")
|
||||
tracks/2/path = NodePath("Smoothing/SpringArm3D:position")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
|
|
@ -63,7 +64,7 @@ tracks/2/keys = {
|
|||
tracks/3/type = "value"
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/path = NodePath("SpringArm3D:rotation")
|
||||
tracks/3/path = NodePath("Smoothing/SpringArm3D:rotation")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/keys = {
|
||||
|
|
@ -78,7 +79,7 @@ resource_name = "death"
|
|||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SpringArm3D:position")
|
||||
tracks/0/path = NodePath("Smoothing/SpringArm3D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
|
|
@ -90,7 +91,7 @@ tracks/0/keys = {
|
|||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("SpringArm3D:rotation")
|
||||
tracks/1/path = NodePath("Smoothing/SpringArm3D:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
|
|
@ -107,7 +108,7 @@ loop_mode = 1
|
|||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/path = NodePath("Smoothing/SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
|
|
@ -119,7 +120,7 @@ tracks/0/keys = {
|
|||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/path = NodePath("Smoothing/SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
|
|
@ -134,7 +135,7 @@ resource_name = "shoot"
|
|||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/path = NodePath("Smoothing/SpringArm3D/Inventory/SpaceGun:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
|
|
@ -146,7 +147,7 @@ tracks/0/keys = {
|
|||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/path = NodePath("Smoothing/SpringArm3D/Inventory/SpaceGun:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
|
|
@ -205,9 +206,10 @@ axis_lock_angular_y = true
|
|||
axis_lock_angular_z = true
|
||||
mass = 75.0
|
||||
physics_material_override = SubResource("PhysicsMaterial_clur0")
|
||||
can_sleep = false
|
||||
continuous_cd = true
|
||||
script = ExtResource("1_mk68k")
|
||||
iff = NodePath("ThirdPerson/IFFAttachment/IFF")
|
||||
iff = NodePath("Smoothing/ThirdPerson/IFF")
|
||||
jump_height = 1.5
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
|
|
@ -234,49 +236,15 @@ shape = ExtResource("2_vjqny")
|
|||
|
||||
[node name="HUD" parent="." instance=ExtResource("3_ccety")]
|
||||
|
||||
[node name="SpringArm3D" type="SpringArm3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
spring_length = 0.0
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="SpringArm3D"]
|
||||
fov = 100.0
|
||||
near = 0.1
|
||||
|
||||
[node name="Inventory" type="Node3D" parent="SpringArm3D"]
|
||||
|
||||
[node name="SpaceGun" parent="SpringArm3D/Inventory" instance=ExtResource("4_ehwwq")]
|
||||
transform = Transform3D(-1, 0, 2.53518e-06, 0, 1, 0, -2.53518e-06, 0, -1, 0.244668, -0.229311, -0.30332)
|
||||
PROJECTILE = ExtResource("5_w56pa")
|
||||
|
||||
[node name="SpineIKTarget" type="Node3D" parent="SpringArm3D"]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
||||
[node name="FlagCarryAttachment" type="Node3D" parent="SpringArm3D"]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.620994, -0.287925)
|
||||
|
||||
[node name="HealthComponent" parent="." instance=ExtResource("5_t6i6e")]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"]
|
||||
shape = ExtResource("2_vjqny")
|
||||
|
||||
[node name="FlagCarryComponent" parent="." node_paths=PackedStringArray("attachment", "sensor") instance=ExtResource("7_e7s1a")]
|
||||
attachment = NodePath("../SpringArm3D/FlagCarryAttachment")
|
||||
attachment = NodePath("../Smoothing/SpringArm3D/FlagCarryAttachment")
|
||||
sensor = NodePath("../Sensor")
|
||||
|
||||
[node name="ThirdPerson" type="Node3D" parent="."]
|
||||
|
||||
[node name="IFFAttachment" type="Marker3D" parent="ThirdPerson"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.1, 0)
|
||||
|
||||
[node name="IFF" parent="ThirdPerson/IFFAttachment" node_paths=PackedStringArray("player", "attach_point") instance=ExtResource("7_8hc80")]
|
||||
player = NodePath("../../..")
|
||||
attach_point = NodePath("..")
|
||||
|
||||
[node name="PlayerMesh" parent="ThirdPerson" node_paths=PackedStringArray("spine_ik_target_attachment") instance=ExtResource("2_beyex")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
spine_ik_target_attachment = NodePath("../../SpringArm3D/SpineIKTarget")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_hg307")
|
||||
|
|
@ -291,3 +259,42 @@ replication_config = SubResource("SceneReplicationConfig_rqdp6")
|
|||
root_path = NodePath(".")
|
||||
replication_config = SubResource("SceneReplicationConfig_5j4ew")
|
||||
script = ExtResource("6_ymcrr")
|
||||
|
||||
[node name="Smoothing" type="Node3D" parent="."]
|
||||
script = ExtResource("11_k330l")
|
||||
target = NodePath("..")
|
||||
flags = 3
|
||||
|
||||
[node name="SpringArm3D" type="SpringArm3D" parent="Smoothing"]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
spring_length = 0.0
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Smoothing/SpringArm3D"]
|
||||
fov = 100.0
|
||||
near = 0.1
|
||||
|
||||
[node name="Inventory" type="Node3D" parent="Smoothing/SpringArm3D"]
|
||||
|
||||
[node name="SpaceGun" parent="Smoothing/SpringArm3D/Inventory" instance=ExtResource("4_6jh57")]
|
||||
transform = Transform3D(-1, 0, 2.53518e-06, 0, 1, 0, -2.53518e-06, 0, -1, 0.244668, -0.229311, -0.30332)
|
||||
PROJECTILE = ExtResource("5_2xh36")
|
||||
|
||||
[node name="SpineIKTarget" type="Node3D" parent="Smoothing/SpringArm3D"]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
||||
[node name="FlagCarryAttachment" type="Node3D" parent="Smoothing/SpringArm3D"]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.620994, -0.287925)
|
||||
|
||||
[node name="ThirdPerson" type="Node3D" parent="Smoothing"]
|
||||
|
||||
[node name="PlayerMesh" parent="Smoothing/ThirdPerson" node_paths=PackedStringArray("spine_ik_target_attachment") instance=ExtResource("2_beyex")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
spine_ik_target_attachment = NodePath("../../SpringArm3D/SpineIKTarget")
|
||||
|
||||
[node name="IFFAttachment" type="Marker3D" parent="Smoothing/ThirdPerson"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.27457, 0)
|
||||
|
||||
[node name="IFF" parent="Smoothing/ThirdPerson" node_paths=PackedStringArray("player", "attach_point") instance=ExtResource("7_8hc80")]
|
||||
player = NodePath("../../..")
|
||||
attach_point = NodePath("../IFFAttachment")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue