Created
December 8, 2016 04:49
-
-
Save sevanspowell/67f008b1836ef4c92b889f551f8f0e99 to your computer and use it in GitHub Desktop.
DraygonTensor - example Lua script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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