Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DraygonTensor - example Lua script
function init()
print("Script: init called!")
cam = Script.spawn_prefab("player", Vector3(0, 0, 0))
Script.spawn_prefab("box", Vector3(0, 0, -10))
end
function shutdown()
print("Script: shutdown called!")
end
function update(deltaTime)
local camOrientation = Quaternion.normalize(Script.get_local_orientation(cam))
local mouseDeltaX, mouseDeltaY = Input.get_mouse_delta_xy()
local yawDelta = Quaternion.create_from_axis_angle(Vector3.unit_y(), -mouseDeltaX * deltaTime)
local pitchDelta = Quaternion.create_from_axis_angle(Vector3.unit_x(), -mouseDeltaY * deltaTime)
camOrientation = (yawDelta * camOrientation * pitchDelta)
Script.set_local_orientation(cam, Quaternion.normalize(camOrientation))
local temp = Vector4.normalize(Vector4.transform(-Vector4.unit_z(), Matrix4.create_from_quaternion(camOrientation)))
local camFwd = Vector3(temp:get_x(), temp:get_y(), temp:get_z())
local temp = Vector4.normalize(Vector4.transform(Vector4.unit_y(), Matrix4.create_from_quaternion(camOrientation)))
local camUp = Vector3(temp:get_x(), temp:get_y(), temp:get_z())
local temp = Vector4.normalize(Vector4.transform(Vector4.unit_x(), Matrix4.create_from_quaternion(camOrientation)))
local camRight = Vector3(temp:get_x(), temp:get_y(), temp:get_z())
local wishDir = Vector3(0, 0, 0)
if (Input.is_key_pressed("w")) then
wishDir = wishDir + camFwd
end
if (Input.is_key_pressed("s")) then
wishDir = wishDir - camFwd
end
if (Input.is_key_pressed("a")) then
wishDir = wishDir - camRight
end
if (Input.is_key_pressed("d")) then
wishDir = wishDir + camRight
end
if (Vector3.magnitude(wishDir) > 0) then
wishDir = Vector3.normalize(wishDir)
wishDir = wishDir * deltaTime * 10
end
Script.set_local_translation(cam, Script.get_local_translation(cam) + wishDir);
-- -- Handle messages
-- while Script.is_next_message() do
-- local msg = Script.get_next_message()
-- print(msg.type)
-- end
end
function render()
--print("Script: render called!")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.