Files
OpenEngine/application/assets/scripts/camera.lua
2026-01-12 16:57:00 +01:00

54 lines
1.4 KiB
Lua

local velocity = 5
function HandleMouse(camera, delta_time)
local mouse_sensitivity = 0.2
local xoffset, yoffset = Input:GetMouseOffset()
xoffset = xoffset * mouse_sensitivity;
yoffset = yoffset * mouse_sensitivity;
local pitch, yaw = camera:GetPitchYaw()
yaw = yaw + xoffset;
pitch = pitch + yoffset;
if pitch > 89.0 then
pitch = 89.0;
if pitch < -89.0 then
pitch = -89.0;
end
end
camera:SetPitchYaw(pitch, yaw)
end
function Update()
local delta_time = Time:DeltaTime();
--local inp = Input:GetKeyStatus(GLFW_KEY_W)
local transform = Parent:GetTransform()
local camera = Parent:GetCamera()
local forward = camera:forward()
local right = camera:right()
local translation
HandleMouse(camera, delta_time)
if Input:GetKeyStatus(GLFW_KEY_W) == 1 then
translation = normalize(forward * vec3:new(1.0, 0.0, 1.0)) * velocity * delta_time
end
if Input:GetKeyStatus(GLFW_KEY_S) == 1 then
translation = normalize(forward * vec3:new(1.0, 0.0, 1.0)) * -velocity * delta_time
end
if Input:GetKeyStatus(GLFW_KEY_A) == 1 then
translation = normalize(right * vec3:new(1.0, 0.0, 1.0)) * -velocity * delta_time
end
if Input:GetKeyStatus(GLFW_KEY_D) == 1 then
translation = normalize(right * vec3:new(1.0, 0.0, 1.0)) * velocity * delta_time
end
transform:Translate(translation)
end