54 lines
1.9 KiB
GDScript
54 lines
1.9 KiB
GDScript
extends Node
|
|
|
|
class_name PlayerMovement
|
|
|
|
const XZ_PLANE = Vector3.RIGHT + Vector3.BACK
|
|
|
|
@export var player: Player
|
|
@export var player_input: PlayerInput
|
|
|
|
@export var jump_velocity: float
|
|
@export_range(0,100,1,"suffix:%") var max_speed_debuff: float
|
|
@export var debuff_time: float = 0.5
|
|
var disabled: bool
|
|
|
|
var speed_debuff: float
|
|
var debuff_tween: Tween
|
|
|
|
func disable() -> void:
|
|
disabled = true
|
|
player.velocity = Vector3.ZERO
|
|
|
|
func process_movement(max_speed: float,acceleration: float,deceleration: float,delta: float) -> void:
|
|
if is_multiplayer_authority() == false:
|
|
return
|
|
if Session.round_state == Session.ROUND_STATES.BUY or disabled or player.passived:
|
|
player.velocity.x = 0
|
|
player.velocity.z = 0
|
|
return
|
|
var input_dir := player_input.direction
|
|
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
if direction:
|
|
var computed_mult : float = (1.-speed_debuff/100.)
|
|
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta * computed_mult,-max_speed*abs(direction.x),max_speed*abs(direction.x))
|
|
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta * computed_mult,-max_speed*abs(direction.z),max_speed*abs(direction.z))
|
|
else:
|
|
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
|
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
|
|
|
func jump() -> void:
|
|
player.velocity.y = jump_velocity
|
|
|
|
func apply_speed_debuff():
|
|
if debuff_tween:
|
|
debuff_tween.kill()
|
|
speed_debuff = max_speed_debuff
|
|
|
|
var xz_velocity: Vector3 = player.velocity * XZ_PLANE
|
|
var new_velocity = xz_velocity * (1.-max_speed_debuff/100.)
|
|
|
|
player.velocity = Vector3(new_velocity.x,player.velocity.y,new_velocity.z)
|
|
|
|
|
|
debuff_tween = create_tween().set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_SINE)
|
|
debuff_tween.tween_property(self,"speed_debuff",0,debuff_time)
|