61 lines
1.6 KiB
Lua
61 lines
1.6 KiB
Lua
local Engine = require("./assets/scripts/engine")
|
|
local KeyCode = require("./assets/scripts/keycode")
|
|
|
|
|
|
local transform = nil
|
|
|
|
local new_rotation = 0
|
|
|
|
local new_rotationSpeed = 15
|
|
local Move_Speec = 300
|
|
|
|
function OnInit()
|
|
local gameObject = Engine.GetGameObjectByTag("Camera")
|
|
transform = gameObject:GetComponent("Transform")
|
|
Engine.Expose("Position X", "nil")
|
|
|
|
Engine.Log("Init Done")
|
|
end
|
|
|
|
function OnUpdate(deltaTime)
|
|
local gameObject = Engine.GetGameObjectByTag("Camera")
|
|
transform = gameObject:GetComponent("Transform")
|
|
|
|
local old_rotation = transform:GetRotation()
|
|
|
|
|
|
|
|
local Position = transform:GetPosition()
|
|
|
|
if Engine.KeyDown(KeyCode.W) then
|
|
Position.x = Position.x + (deltaTime * Move_Speec)
|
|
end
|
|
if Engine.KeyDown(KeyCode.S) then
|
|
Position.x = Position.x - (deltaTime * Move_Speec)
|
|
end
|
|
if Engine.KeyDown(KeyCode.D) then
|
|
Position.z = Position.z + (deltaTime * Move_Speec)
|
|
end
|
|
if Engine.KeyDown(KeyCode.A) then
|
|
Position.z = Position.z - (deltaTime * Move_Speec)
|
|
end
|
|
|
|
transform:SetPosition(Position)
|
|
|
|
Engine.Expose("Position X", Position.x)
|
|
|
|
|
|
|
|
local rotation = {
|
|
x = old_rotation.x, -- Preserving existing new_rotation on X-axis
|
|
y = new_rotation, -- Updated new_rotation on Y-axis for spinning
|
|
z = old_rotation.z -- Preserving existing new_rotation on Z-axis
|
|
}
|
|
-- Apply the new new_rotation to the Transform component
|
|
transform:SetRotation(rotation)
|
|
new_rotation = new_rotation + (deltaTime * new_rotationSpeed)
|
|
if new_rotation >= 360 then
|
|
new_rotation = 0
|
|
end
|
|
end
|