Okay, then maybe it will be useful to someone in the future.
function init(self)
msg.post(".", "acquire_input_focus")
msg.post("@render:", "use_camera_projection")
msg.post("camera", "acquire_camera_focus")
self.speed_rotation = 10
self.speed = 6
self.bindings = {
forward = hash 'key_w',
backward = hash 'key_s',
left = hash 'key_a',
right = hash 'key_d'
}
self.input = {
forward = nil,
backward = nil,
left = nil,
right = nil
}
end
function update(self, dt)
local direction = vmath.vector3()
local input = self.input
if input.forward then
direction.z = -1
elseif input.backward then
direction.z = 1
end
if input.right then
direction.x = 1
elseif input.left then
direction.x = -1
end
if vmath.length(direction) >= 1 then
direction = vmath.normalize(direction)
end
if vmath.length(direction) > 0 then
local angle = math.atan2(-direction.x, -direction.z)
local quat = vmath.quat_rotation_y(angle)
local my_rotation = go.get_rotation()
print(go.get_rotation())
go.set_rotation(vmath.slerp(dt * self.speed_rotation, my_rotation, quat))
end
go.set_position(go.get_position()+direction*dt*self.speed)
end
function on_input(self, action_id, action)
if not action_id then
return
end
if action_id == self.bindings.right then
self.input.right = not action.released or nil
elseif action_id == self.bindings.left then
self.input.left = not action.released or nil
end
if action_id == self.bindings.forward then
self.input.forward = not action.released or nil
elseif action_id == self.bindings.backward then
self.input.backward = not action.released or nil
end
end