CameraExampleCode
From Crumbled World Wiki
Example Code
--this = Camera()
function create()
keyBinds = Core.getBillboard("keyBind");
keyBindForward = keyBinds:getKeyBind("forward");
keyBindBackward = keyBinds:getKeyBind("backward");
keyBindLeft = keyBinds:getKeyBind("left");
keyBindRight = keyBinds:getKeyBind("right");
end
function update()
local deltaTime = Core.getDeltaTime()
local localMat = this:getLocalMatrix()
if keyBindForward:getHeld() then
localMat:setPosition( localMat:getPosition() - localMat:getAtVec() * deltaTime * 20 )
end
if keyBindBackward:getHeld() then
localMat:setPosition( localMat:getPosition() + localMat:getAtVec() * deltaTime * 20 )
end
if keyBindLeft:getHeld() then
localMat:setPosition( localMat:getPosition() - localMat:getRightVec() * deltaTime * 20 )
end
if keyBindRight:getHeld() then
localMat:setPosition( localMat:getPosition() + localMat:getRightVec() * deltaTime * 20 )
end
--update rotate
if Core.getInput():getKeyHeld(Key.space) then
local moseDiff = Core.getInput():getMouseDelta() * 0.002
quatRot = Quat()
quatRot:fromEuler(moseDiff.y, moseDiff.x, 0.0)
localMat = localMat * quatRot:getMatrix()
end
this:setLocalMatrix(localMat)
return true
end