mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-20 03:54:47 +00:00
Merge branch 'feat/aerial_control' into 'develop'
🐛 Aerial control, small refactoring and dummy target fix See merge request open-fpsz/open-fpsz!31
This commit is contained in:
commit
dc7896a591
|
|
@ -1,49 +1,46 @@
|
|||
extends RigidBody3D
|
||||
class_name Player
|
||||
class_name Player extends RigidBody3D
|
||||
|
||||
enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
|
||||
|
||||
# constants
|
||||
const max_energy : float = 100.0
|
||||
const energy_charge_rate : float = 10 # energy per second
|
||||
const energy_drain_rate : float = 20 # energy per second
|
||||
const ground_speed : float = 48 / 3.6 # m/s
|
||||
const jetpack_vertical_force : float = 800
|
||||
const jetpack_horizontal_force : float = 400
|
||||
const jetpack_force_factor : float = 2
|
||||
|
||||
# parameters
|
||||
@export_category("Parameters")
|
||||
@export var ground_speed : float = 48 / 3.6 # m/s
|
||||
@export var aerial_control_force : int = 400
|
||||
@export var max_floor_angle : float = 60
|
||||
@export var energy: float = 100.0
|
||||
var g : float = ProjectSettings.get_setting("physics/3d/default_gravity") # in m/s²
|
||||
var gravity : Vector3 = g * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
|
||||
|
||||
@export_group("Jetpack")
|
||||
@export var energy: float = 100.0
|
||||
@export var energy_charge_rate : float = 20 # energy per second
|
||||
@export var energy_drain_rate : float = 25 # energy per second
|
||||
@export var energy_max : float = 100.
|
||||
@export var jetpack_force_factor : float = 2.
|
||||
@export var jetpack_horizontal_force : float = 600
|
||||
@export var jetpack_vertical_force : float = 800
|
||||
|
||||
@export_group("State")
|
||||
@export var player_state = PlayerState.PLAYER_ALIVE
|
||||
@export var player_id = 1:
|
||||
set(id):
|
||||
player_id = id
|
||||
$PlayerInput.set_multiplayer_authority(id)
|
||||
|
||||
@export var player_state = PlayerState.PLAYER_ALIVE
|
||||
|
||||
@onready var input : PlayerInput = $PlayerInput
|
||||
@onready var camera = $SpringArm3D/Camera3D
|
||||
|
||||
@onready var hud = $HUD
|
||||
@onready var iff = $ThirdPerson/IFF
|
||||
@onready var shape_cast = $ShapeCast3D
|
||||
@onready var weapon = $SpringArm3D/Inventory/SpaceGun
|
||||
@onready var animation_player : AnimationPlayer = $AnimationPlayer
|
||||
@onready var health_component = $HealthComponent
|
||||
|
||||
@onready var spring_arm_height = $SpringArm3D.position.y
|
||||
@onready var _original_weapon_transform : Transform3D = weapon.transform
|
||||
|
||||
signal died(player)
|
||||
signal energy_changed(energy)
|
||||
|
||||
var g : float = ProjectSettings.get_setting("physics/3d/default_gravity") # in m/s²
|
||||
var gravity : Vector3 = g * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
|
||||
var _jumping = false
|
||||
|
||||
@onready var _original_weapon_transform : Transform3D = weapon.transform
|
||||
|
||||
func _ready():
|
||||
energy_changed.connect(hud._on_energy_changed)
|
||||
health_component.health_changed.connect(hud._on_health_changed)
|
||||
|
|
@ -80,12 +77,16 @@ func _jump():
|
|||
return
|
||||
_jumping = true
|
||||
|
||||
func _is_on_floor() -> bool:
|
||||
func is_on_floor() -> bool:
|
||||
return shape_cast.is_colliding()
|
||||
|
||||
func _is_skiing() -> bool:
|
||||
return input.skiing
|
||||
|
||||
func _handle_aerial_control(delta, direction):
|
||||
if not input.jetting and not is_on_floor():
|
||||
apply_force(direction * aerial_control_force)
|
||||
|
||||
func _handle_jetpack(delta, direction):
|
||||
if input.jetting:
|
||||
if energy > 0:
|
||||
|
|
@ -96,7 +97,7 @@ func _handle_jetpack(delta, direction):
|
|||
else:
|
||||
energy += energy_charge_rate * delta
|
||||
|
||||
energy = clamp(energy, 0, max_energy)
|
||||
energy = clamp(energy, 0, energy_max)
|
||||
energy_changed.emit(energy)
|
||||
|
||||
func _process(_delta):
|
||||
|
|
@ -127,6 +128,7 @@ func _physics_process(delta):
|
|||
# adjust direction based on spring arm rotation
|
||||
_direction = _direction.rotated(Vector3.UP, $SpringArm3D.rotation.y)
|
||||
|
||||
_handle_aerial_control(delta, _direction)
|
||||
_handle_jetpack(delta, _direction)
|
||||
|
||||
# handle ski
|
||||
|
|
@ -135,7 +137,7 @@ func _physics_process(delta):
|
|||
else:
|
||||
physics_material_override.friction = 1
|
||||
|
||||
if _is_on_floor():
|
||||
if is_on_floor():
|
||||
if not _direction.is_zero_approx() and not _is_skiing():
|
||||
# retrieve collision normal
|
||||
var normal = shape_cast.get_collision_normal(0)
|
||||
|
|
@ -163,7 +165,7 @@ func _update_third_person_animations():
|
|||
tp_player.set_ground_state(Vanguard.GroundState.GROUND_STATE_DEAD)
|
||||
return
|
||||
|
||||
if _is_on_floor():
|
||||
if is_on_floor():
|
||||
tp_player.set_ground_state(Vanguard.GroundState.GROUND_STATE_GROUNDED)
|
||||
else:
|
||||
tp_player.set_ground_state(Vanguard.GroundState.GROUND_STATE_MID_AIR)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
extends MultiplayerSynchronizer
|
||||
class_name PlayerInput
|
||||
class_name PlayerInput extends MultiplayerSynchronizer
|
||||
|
||||
@export var jetting = false
|
||||
@export var skiing = false
|
||||
@export var direction = Vector2.ZERO
|
||||
@export var camera_rotation : Vector2
|
||||
@export var MOUSE_SENSITIVITY : float = 1.0
|
||||
@export var MOUSE_SENSITIVITY : float = .6
|
||||
|
||||
signal jumped
|
||||
signal fired_primary
|
||||
|
|
@ -35,6 +34,8 @@ func _process(delta):
|
|||
_fire_primary.rpc()
|
||||
jetting = Input.is_action_pressed("jump_and_jet")
|
||||
skiing = Input.is_action_pressed("ski")
|
||||
|
||||
func _physics_process(delta):
|
||||
_update_camera(delta)
|
||||
|
||||
@rpc("call_local")
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ nodes/root_name=""
|
|||
nodes/apply_root_scale=true
|
||||
nodes/root_scale=1.0
|
||||
meshes/ensure_tangents=true
|
||||
meshes/generate_lods=true
|
||||
meshes/generate_lods=false
|
||||
meshes/create_shadow_meshes=true
|
||||
meshes/light_baking=1
|
||||
meshes/lightmap_texel_size=0.2
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ bones/27/scale = Vector3(1, 1, 1)
|
|||
bones/28/rotation = Quaternion(-0.144176, 0.0367847, -0.00247504, 0.988865)
|
||||
bones/28/scale = Vector3(1, 1, 1)
|
||||
bones/30/rotation = Quaternion(-0.0630717, 0.16283, -0.0971492, 0.979832)
|
||||
bones/30/scale = Vector3(1, 1, 1)
|
||||
bones/31/rotation = Quaternion(0.0237032, 0.0123211, -0.0433656, 0.998702)
|
||||
bones/31/scale = Vector3(1, 1, 1)
|
||||
bones/32/rotation = Quaternion(0.243143, 0.523041, 0.164477, 0.800161)
|
||||
|
|
|
|||
|
|
@ -89,4 +89,3 @@ toggle_mouse_capture={
|
|||
|
||||
3d/physics_engine="JoltPhysics3D"
|
||||
3d/default_gravity=19.6
|
||||
3d/default_linear_damp=0.01
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ func _test_projectile_class():
|
|||
var projectile = Projectile.new()
|
||||
assert(projectile != null, "Projectile class should be instantiated")
|
||||
assert(projectile.speed == 78.4, "Projectile damage should be initialized to 78.4")
|
||||
projectile.queue_free()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue