add acceleration to player

This commit is contained in:
Lera Elvoé 2025-02-14 22:03:18 +03:00
parent a0ba6f9da3
commit ea4504bdb4
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc

View File

@ -10,6 +10,8 @@ local Player = {
yaw = 0,
yaw_speed = 0.05,
accel = 0.3,
ThrowPressed = Signal.new(),
}
@ -20,7 +22,7 @@ function Player:tick(ctx)
input_action{name = "forward", control = "W"}
input_action{name = "back", control = "S"}
input_action{name = "throw", control = "SPACE"}
input_action{name = "throw", control = "LCLICK"}
local camera_forward = Vector3(draw_camera_from_principal_axes(self).direction)
camera_forward.y = 0
@ -31,7 +33,9 @@ function Player:tick(ctx)
local strafe_input = util.b2n(input_action_pressed{name = "right"}) - util.b2n(input_action_pressed{name = "left"})
local direction = ((camera_forward * forward_input) + (camera_right * strafe_input)):normalized()
self.velocity = direction * self.speed
local target_vel = direction * self.speed
self.velocity = self.velocity:lerp(target_vel, self.accel)
-- self.velocity = target_vel
if input_action_just_pressed{name = "throw"} then
self.ThrowPressed:emit(self.position:copy(), camera_forward:copy())