Files
dusk/assets/entities/player.lua
T
2026-04-21 08:39:50 -05:00

47 lines
1.0 KiB
Lua

module('entity')
module('input')
module('color')
module('math')
module('scene')
module('event')
module('entitycamera')
local phys
local updateSub
local SPEED = 4.0
function entityInit()
local pos = entityPositionAdd(ENTITY_ID)
pos.x = 0
pos.y = 1
pos.z = 0
phys = entityPhysicsAdd(ENTITY_ID)
phys:setShapeCapsule(0.3, 0.9)
local mesh = entityMeshAdd(ENTITY_ID)
mesh:generateCapsule(0.3, 0.9)
local mat = entityMaterialAdd(ENTITY_ID)
mat.color = colorBlue()
updateSub = eventSubscribe(SCENE_EVENT_UPDATE, onUpdate)
end
function onUpdate()
local moveX = inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT)
local moveZ = inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP)
local cam = entityCameraGetCurrent()
local fwd = cam:getForward()
local right = cam:getRight()
local vy = phys.velocityY
phys.velocityX = (moveX * right.x + moveZ * fwd.x) * SPEED
phys.velocityZ = (moveX * right.y + moveZ * fwd.y) * SPEED
end
function entityDispose()
eventUnsubscribe(SCENE_EVENT_UPDATE, updateSub)
end