movement system rework
This commit is contained in:
parent
900502ec8a
commit
792465a33c
7 changed files with 47 additions and 31 deletions
|
|
@ -1,6 +1,8 @@
|
|||
extends State
|
||||
|
||||
@export var speed: float = 5.0
|
||||
@export var max_speed: float = 5.0
|
||||
@export var acceleration: float = 2.0
|
||||
@export var deceleration: float = 200.0
|
||||
@export var JUMP_VELOCITY: float = 4.5
|
||||
@export var player: Player
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
|
@ -11,7 +13,7 @@ func enter() -> void:
|
|||
func exit() -> void:
|
||||
pass
|
||||
|
||||
func physics_update(_delta: float) -> void:
|
||||
func physics_update(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor():
|
||||
|
|
@ -25,13 +27,13 @@ func physics_update(_delta: float) -> void:
|
|||
|
||||
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
var modified_speed := speed * weapon_system.get_speed_modifier()
|
||||
var modified_max_speed = max_speed * weapon_system.get_speed_modifier()
|
||||
if direction:
|
||||
player.velocity.x = direction.x * modified_speed
|
||||
player.velocity.z = direction.z * modified_speed
|
||||
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-modified_max_speed*abs(direction.x),modified_max_speed*abs(direction.x))
|
||||
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z))
|
||||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, modified_speed)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, modified_speed)
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("plr_crouch"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue