add throw signal to player

This commit is contained in:
2025-02-14 15:17:05 +03:00
parent aff1bfd247
commit 2515fe7b27
3 changed files with 20 additions and 0 deletions

View File

@ -1,5 +1,6 @@
local Vector3 = require("types.vector3")
local util = require("util")
local Signal = require("types.signal")
local Player = {
position = Vector3(0, 1, 0),
@ -10,6 +11,8 @@ local Player = {
yaw = 0,
yaw_speed = 0.05,
ThrowPressed = Signal.new(),
}
function Player:tick(ctx)
@ -18,6 +21,8 @@ function Player:tick(ctx)
input_action{name = "forward", control = "W"}
input_action{name = "back", control = "S"}
input_action{name = "throw", control = "SPACE"}
local camera_forward = Vector3(draw_camera_from_principal_axes(self).direction)
camera_forward.y = 0
camera_forward = camera_forward:normalized()
@ -29,6 +34,10 @@ function Player:tick(ctx)
local direction = ((camera_forward * forward_input) + (camera_right * strafe_input)):normalized()
self.velocity = direction * self.speed
if input_action_just_pressed{name = "throw"} then
self.ThrowPressed:emit(self.position:copy(), camera_forward:copy())
end
if ctx.mouse_capture then
self.yaw = self.yaw + self.mouse_sensitivity * ctx.mouse_movement.x
end