Compare commits
No commits in common. "ea4504bdb440334d3d8978be65b21d4cff572eed" and "e19943e9f228634f5c4514c487e9b596ef826dc0" have entirely different histories.
ea4504bdb4
...
e19943e9f2
@ -1,4 +1,5 @@
|
|||||||
local Vector3 = require "types.vector3"
|
local Vector3 = require "types.vector3"
|
||||||
|
local util = require "util"
|
||||||
|
|
||||||
local TEXTURE = "images/tongue.png"
|
local TEXTURE = "images/tongue.png"
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
local Vector3 = require("types.vector3")
|
local Vector3 = require("types.vector3")
|
||||||
|
local util = require("util")
|
||||||
local Signal = require("types.signal")
|
local Signal = require("types.signal")
|
||||||
|
|
||||||
local Player = {
|
local Player = {
|
||||||
@ -11,8 +12,6 @@ local Player = {
|
|||||||
yaw = 0,
|
yaw = 0,
|
||||||
yaw_speed = 0.05,
|
yaw_speed = 0.05,
|
||||||
|
|
||||||
accel = 0.3,
|
|
||||||
|
|
||||||
ThrowPressed = Signal.new(),
|
ThrowPressed = Signal.new(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ function Player:tick(ctx)
|
|||||||
input_action{name = "forward", control = "W"}
|
input_action{name = "forward", control = "W"}
|
||||||
input_action{name = "back", control = "S"}
|
input_action{name = "back", control = "S"}
|
||||||
|
|
||||||
input_action{name = "throw", control = "LCLICK"}
|
input_action{name = "throw", control = "SPACE"}
|
||||||
|
|
||||||
local camera_forward = Vector3(draw_camera_from_principal_axes(self).direction)
|
local camera_forward = Vector3(draw_camera_from_principal_axes(self).direction)
|
||||||
camera_forward.y = 0
|
camera_forward.y = 0
|
||||||
@ -33,9 +32,7 @@ function Player:tick(ctx)
|
|||||||
local strafe_input = util.b2n(input_action_pressed{name = "right"}) - util.b2n(input_action_pressed{name = "left"})
|
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()
|
local direction = ((camera_forward * forward_input) + (camera_right * strafe_input)):normalized()
|
||||||
local target_vel = direction * self.speed
|
self.velocity = direction * self.speed
|
||||||
self.velocity = self.velocity:lerp(target_vel, self.accel)
|
|
||||||
-- self.velocity = target_vel
|
|
||||||
|
|
||||||
if input_action_just_pressed{name = "throw"} then
|
if input_action_just_pressed{name = "throw"} then
|
||||||
self.ThrowPressed:emit(self.position:copy(), camera_forward:copy())
|
self.ThrowPressed:emit(self.position:copy(), camera_forward:copy())
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
util = require "util"
|
|
||||||
local player = require "classes.player"
|
local player = require "classes.player"
|
||||||
|
local util = require "util"
|
||||||
local Vector3 = require "types.vector3"
|
local Vector3 = require "types.vector3"
|
||||||
|
|
||||||
local Feed = require "classes.feed"
|
local Feed = require "classes.feed"
|
||||||
|
|
||||||
local feed = {}
|
local feed = {}
|
||||||
|
|
||||||
local function create_feed(position, direction)
|
local function create_feed(position, direction)
|
||||||
|
@ -3,6 +3,8 @@ local Signal = {
|
|||||||
_connections = {}
|
_connections = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local util = require "util"
|
||||||
|
|
||||||
Signal.__index = Signal
|
Signal.__index = Signal
|
||||||
|
|
||||||
---Connects f to this signal. When the signal is emmitted, this function will be called.
|
---Connects f to this signal. When the signal is emmitted, this function will be called.
|
||||||
|
@ -216,25 +216,6 @@ end
|
|||||||
function Vector3:copy()
|
function Vector3:copy()
|
||||||
return Vector3(self)
|
return Vector3(self)
|
||||||
end
|
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
|
---- CONSTANTS
|
||||||
|
|
||||||
Vector3.UP = Vector3(0, 1, 0)
|
Vector3.UP = Vector3(0, 1, 0)
|
||||||
|
@ -97,24 +97,4 @@ function util.list_insert_once(t, value)
|
|||||||
if util.list_find(t, value) ~= -1 then return end
|
if util.list_find(t, value) ~= -1 then return end
|
||||||
table.insert(t, value)
|
table.insert(t, value)
|
||||||
end
|
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
|
return util
|
Loading…
Reference in New Issue
Block a user