Compare commits
3 Commits
e19943e9f2
...
ea4504bdb4
Author | SHA1 | Date | |
---|---|---|---|
ea4504bdb4 | |||
a0ba6f9da3 | |||
a532325cd2 |
@ -1,5 +1,4 @@
|
||||
local Vector3 = require "types.vector3"
|
||||
local util = require "util"
|
||||
|
||||
local TEXTURE = "images/tongue.png"
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
local Vector3 = require("types.vector3")
|
||||
local util = require("util")
|
||||
local Signal = require("types.signal")
|
||||
|
||||
local Player = {
|
||||
@ -11,6 +10,8 @@ local Player = {
|
||||
|
||||
yaw = 0,
|
||||
yaw_speed = 0.05,
|
||||
|
||||
accel = 0.3,
|
||||
|
||||
ThrowPressed = Signal.new(),
|
||||
}
|
||||
@ -21,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
|
||||
@ -32,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())
|
||||
|
@ -1,8 +1,8 @@
|
||||
util = require "util"
|
||||
local player = require "classes.player"
|
||||
local util = require "util"
|
||||
local Vector3 = require "types.vector3"
|
||||
local Feed = require "classes.feed"
|
||||
|
||||
local Feed = require "classes.feed"
|
||||
local feed = {}
|
||||
|
||||
local function create_feed(position, direction)
|
||||
|
@ -3,8 +3,6 @@ local Signal = {
|
||||
_connections = {}
|
||||
}
|
||||
|
||||
local util = require "util"
|
||||
|
||||
Signal.__index = Signal
|
||||
|
||||
---Connects f to this signal. When the signal is emmitted, this function will be called.
|
||||
|
@ -216,6 +216,25 @@ end
|
||||
function Vector3:copy()
|
||||
return Vector3(self)
|
||||
end
|
||||
|
||||
---Returns a new vector as a linear interpolation between self and b.
|
||||
---@param b vectorlike
|
||||
---@param t number
|
||||
---@return Vector3
|
||||
function Vector3:lerp(b, t)
|
||||
-- return self:copy()
|
||||
if not is_weak_vector3(b) then
|
||||
error("Vector3: b must be a Vector3-like table. Returning copy of self.")
|
||||
return self:copy()
|
||||
end
|
||||
local w = Vector3(b)
|
||||
return Vector3{
|
||||
util.lerp(self.x, w.x, t),
|
||||
util.lerp(self.y, w.y, t),
|
||||
util.lerp(self.z, w.z, t),
|
||||
}
|
||||
end
|
||||
|
||||
---- CONSTANTS
|
||||
|
||||
Vector3.UP = Vector3(0, 1, 0)
|
||||
|
@ -97,4 +97,24 @@ function util.list_insert_once(t, value)
|
||||
if util.list_find(t, value) ~= -1 then return end
|
||||
table.insert(t, value)
|
||||
end
|
||||
|
||||
---linear interpolation
|
||||
---@param a number
|
||||
---@param b number
|
||||
---@param t number in [0, 1]
|
||||
---@return number
|
||||
function util.lerp(a, b, t)
|
||||
return a + t * (b - a)
|
||||
end
|
||||
|
||||
---constrains v between min and max
|
||||
---@param v number
|
||||
---@param min number
|
||||
---@param max number
|
||||
---@return number
|
||||
function util.clamp(v, min, max)
|
||||
return math.max(math.min(v, max), min)
|
||||
end
|
||||
|
||||
|
||||
return util
|
Loading…
Reference in New Issue
Block a user