19 lines
812 B
GDScript
19 lines
812 B
GDScript
class_name PlayerMovement
|
|
extends Node
|
|
|
|
# Pure movement calculation: no weapon node, HUD, parent lookup or network call.
|
|
func calculate(current: Vector3, axis: Vector2, yaw: float, sprint: bool, crouched: bool, aiming: bool, sliding: bool, grounded: bool, jump: bool, speed_multiplier: float, dt: float) -> Vector3:
|
|
var speed := 8.7 if sprint else 5.8
|
|
if crouched: speed = 3.1
|
|
if aiming: speed *= 0.68
|
|
speed *= speed_multiplier
|
|
var direction := Basis(Vector3.UP, yaw) * Vector3(axis.x,0,axis.y)
|
|
if sliding:
|
|
speed = 10.8
|
|
if direction.length() < 0.1: direction = Basis(Vector3.UP,yaw) * Vector3.FORWARD
|
|
current.x = move_toward(current.x,direction.x*speed,dt*65)
|
|
current.z = move_toward(current.z,direction.z*speed,dt*65)
|
|
if not grounded: current.y -= 23*dt
|
|
elif jump: current.y = 7.0
|
|
return current
|