Open Dev Kit Documentation :: Demo - Turtle 3D
Demo project showcasing 3D robotics with physics taught through simple Lua scripts; great resource for students learning how to program. Users can control a turtle (or other spawnedHow it Works
- Demo Initialization
- The demo starts with a turtle already placed in a 3D environment. The interface includes multiple UI
Windows : theMain view, where the scene is rendered; theControls window, which allows users to build Lua scripts for programming the turtle; theHUD window, displaying various properties about the selected object; and theObject Spawner window, which shows up when creating new objects. A secondaryPreview Scene is loaded for the HUD's top-down view. The additional windows are loaded via theStart function which executes upon starting the demo. - Programming Spawned Objects
- Users interact with the
x = The actor ID, which identifies the specific object to control.COMMAND = The action to perform (e.g. movement, rotation).parameters = Additional values required for the command.
Controls Window , which provides pre-defined command buttons that insert Lua script lines into aTextbox . Alternatively, users can also write their own Lua scripts directly. Changing the script, or clickingRun Script ifAuto Execute is not ticked, will cause the script to execute the commands linearly via Lua evaluation, instructing the turtle (or any spawned object) to move, rotate, draw a line on its path, or perform other programmed actions. You can edit the line's properties via theDefaultLine variable found in .Tools >Globals / API
Commands follow a structured format using Lua scripting. Each command targets a specific object using its actor ID within theObjects Array and applies a function to modify its state.
Command Structure: Objects[x]:COMMAND(parameters) - Spawning a New Object
- You can spawn new objects by clicking
New in theControls Window , which opens theObject Spawner . ThisWindow allows setting properties for that object such as name, its graphic model, position, scale, color and physics. After configuring the settings, clickingSpawn Object will add the new actor to theScene , where it can be controlled via Lua commands using its unique identifier number.
Adding New Spawnable Objects
Follow these steps to add a new object to the demo:
- Create the New Object:
- Open
.Tools >Resources - Double-click the
Sprites Sprite Resource . - Select an empty tile and click the
Import Images/Model icon to import your graphic model. You may have to configure its scale and rotation. - Depending on the shape of the model you are importing, click the
Add Box Collision /Add Capsule Collision icon ("Shared with whole Tile") to add a new collision box to theSprite Editor . - Line it up with the model.
- Open
- Set up the New Shape:
- Open
.Tools >Globals / API - Select the
ObjectTemplates variable. - Since there is now a new object, we will increase the
Default Object count by clicking+ once besideDefault Object . - Head down until you find the new entry (labeled "[9]") and set its
Sprite Tile to6 if the new object was created on the 7th tile (the count starts from 0, therefore the 7th tile's # would be 6). - Configure the rest of its properties as you see fit.
- Open
- Test the Game:
- That's it! Run the project to verify the new object is now selectable in the
Object Spawner Window's dropdown list.
Adding a New Command: Set Color
Follow these steps to add a new command to the demo for changing the color of an object:
- Update API:
- Open
.Tools >Globals / API - Create a new function for the
Object class calledSetColor . - Add a function parameter for that function called
Color , and set its type toRoot.ColorHDR . - Click
Edit Function Script to add color-changing functionality using theChange Tint Color function (found under theActor category or by using the search filter):Identifier =this Value =Color
- Open
- Create the New Command Button:
- Open the
Controls Window . - Since this command is about color, we can simply copy-paste the
btnDrawColor Button and only do minor changes to it, considering it has very similar functionality. - Update the
Button's Clicked Event :- Set
Change Text 's value totxtScript.Text & "\n" & "Objects[" & lbCurrentObject.SelectedIndex + 1 & "]:SetColor(Root.ColorHDR(" & GUI.ColorDialogSelectionHDR.Red & "," & GUI.ColorDialogSelectionHDR.Green & "," & GUI.ColorDialogSelectionHDR.Blue & "," & GUI.ColorDialogSelectionHDR.Alpha &"));"
Essentially, we're just changing the - Set
... + 1 & "]:_Set_DrawColor(Root.ColorHDR ... part of the value to... + 1 & "]:SetColor(Root.ColorHDR ... so it reflects the name of the new function we created, which is "SetColor". - Open the
- Test the Application:
- Run the project to verify the new command works as expected.
Sample Scripts
Copy these scripts into the Lua textbox of the
Squigly Cylinder
local a = 0
while a < 18 do
Objects[1]:_Set_DrawColor(Root.ColorHDR(a / 18,1,1,1));
Objects[1]:Elevate(100);
Objects[1]:Forward(20);
Objects[1]:RotateLeft(10);
Objects[1]:Descend(100);
Objects[1]:Forward(20);
Objects[1]:RotateLeft(10);
a = a + 1;
end
Circle
local a = 0
while a < 360 do
Objects[1]:Forward(2);
Objects[1]:RotateLeft(1);
a = a + 1;
end
Square
Objects[1]:Teleport(Root.Vector3(-250,0,0));
Objects[1]:Forward(500);
Objects[1]:RotateLeft(90);
Objects[1]:Forward(500);
Objects[1]:RotateLeft(90);
Objects[1]:Forward(500);
Objects[1]:RotateLeft(90);
Objects[1]:Forward(500);
Chaotic
Objects[1]:Teleport(Root.Vector3(0,-250,0));
local a = 0
local b = 0
while b < 375 do
Objects[1]:Forward(a);
Objects[1]:RotateRight(b);
a = a + 3
b = b + 1
end
Spiral
Objects[1]:_Set_Drawing(1);
local a = 0
while a < 1080 do
Objects[1]:_Set_DrawColor(Root.ColorHDR(a/1080,a/1080,a/1080,1));
Objects[1]:Forward(a);
Objects[1]:RotateLeft(59);
a = a + 1;
end
Fractal
Objects[1]:Teleport(Root.Vector3(0,600,0));
Objects[1]:RotateLeft(90);
Objects[1]:FractalTree(200,30,7);
If you think anything is missing, please feel free to: submit documentation feedback on this page