Skip to content

Example use case

Ethan Bond edited this page Feb 2, 2021 · 1 revision

Firstly the Advanced Drone Prefab must setup and added to the scene using the installation and setup page in this guide.

Once the Prefab is set up, add in the Target prefab and move it to any location approximately 100m away from the drone prefab.

Next create an empty GameObject, rename it "Sub_Manager", and attach the "Sub_Manager_Example_Script". The expectation is for every experiment you will want to write a custom "Sub_manager" and "Simulation_manager" class.

Next attach the SaveData script to the Sub_manager following the SaveData UserGuide to set it up. The script/instance should be set to "Sub_Manager", and the fields to save "Time_Elapsed" and "Drone_DF".

Finally, you will need to create a simulation manager, create an empty GameObject, rename it "Simulation_Manager" and add the "Simulation_Manager_Example" script to it. In the inspector of the simulation manager you can now select a maximum and minimum and drag factor value and a resolution, the resolution is the number of values it try between the min and max including the min and max. Set these value to whatever you want and then press run.

A text file will now have been generated in the path selected in savedata.

To speed up the simulator you can go file -> project settings -> time -> timescale and then set it to 100. Unity has a maximum timescale of 100 meaning it can only run at 100 times real time. For a lot of large simulations this is not feasible thus parallel runs is the way forward.

To modify your simulation to run in parallel you will need to assemble everything as prefab and then have instantiate copies using the simulation manager.

Begin by create an empty gameobject and calling is Simulation_Prefab, drag the Simulation Prefab into the explorer and then delete all the files in the hierarchy so it looks like the following.

Next open the simulation_manager script and add in the following code.

Then save the script and open the inspector for the simulation_manager, drag the simulation_prefab you just created and place it in the simulation_prefab. While in the inspector you can select the number of worker to instantiate. Set this to 10 then start the simulation. The simulation should complete faster and the data appended to the end of the first SaveData file. If the simulation does not complete significantly faster it is likely your PCs performance was being maxed out already.