Thanks to the new mesh features I’m inspired to work with 3D again and relearning / making useful things for me. Here is a very basic camera view movement and rotation script. If you setup the proper keys in input and attach this script to a GO which has our camera on you can use it to move around a 3D scene in a way useful for general inspection.
V1 because it’s a first fresh attempt and I intend to make it fancier in future versions. If you have a similar kind of script please contribute! I would like to make versions of every popular camera style. I’ll turn this into a proper project later.
V1
local turn_speed = 0.01
local move_speed = 0.25
local forward = vmath.vector3(0,0,-1)
local backward = vmath.vector3(0,0,1)
local left = vmath.vector3(-1,0,0)
local right = vmath.vector3(1,0,0)
local function move(v)
local position = go.get_position()
local rotation = go.get_rotation()
local direction = vmath.rotate(rotation, v)
position = position + direction * move_speed
go.set_position(position)
end
function init(self)
msg.post(".", "acquire_input_focus")
end
function final(self)
-- Add finalization code here
-- Remove this function if not needed
end
function update(self, dt)
-- Add update code here
-- Remove this function if not needed
end
function on_message(self, message_id, message, sender)
-- Add message-handling code here
-- Remove this function if not needed
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.released == false then
local rotation = go.get_rotation()
local direction_x
local direction_y
if action.dx then
if action.dx > 0 then
rotation = rotation * vmath.quat_axis_angle(vmath.vector3(0,-1,0), turn_speed * math.abs(action.dx))
else
rotation = rotation * vmath.quat_axis_angle(vmath.vector3(0,1,0), turn_speed * math.abs(action.dx))
end
end
if action.dy then
if action.dy > 0 then
rotation = rotation * vmath.quat_axis_angle(vmath.vector3(1,0,0), turn_speed * math.abs(action.dy))
else
rotation = rotation * vmath.quat_axis_angle(vmath.vector3(-1,0,0), turn_speed * math.abs(action.dy))
end
end
go.set_rotation(rotation)
end
if action_id == hash("key_w") and action.released == false then
move(forward)
end
if action_id == hash("key_s") and action.released == false then
move(backward)
end
if action_id == hash("key_a") and action.released == false then
move(left)
end
if action_id == hash("key_d") and action.released == false then
move(right)
end
end
function on_reload(self)
-- Add reload-handling code here
-- Remove this function if not needed
end