jtatman commited on
Commit
024fc31
1 Parent(s): cf11f02

Upload folder using huggingface_hub

Browse files
Files changed (45) hide show
  1. README.md +25 -0
  2. Spaceship.csproj +10 -0
  3. Spaceship.sln +19 -0
  4. addons/godot_rl_agents/controller/ai_controller_2d.gd +82 -0
  5. addons/godot_rl_agents/controller/ai_controller_3d.gd +80 -0
  6. addons/godot_rl_agents/godot_rl_agents.gd +16 -0
  7. addons/godot_rl_agents/icon.png +3 -0
  8. addons/godot_rl_agents/onnx/csharp/ONNXInference.cs +118 -0
  9. addons/godot_rl_agents/onnx/csharp/SessionConfigurator.cs +131 -0
  10. addons/godot_rl_agents/onnx/csharp/docs/ONNXInference.xml +31 -0
  11. addons/godot_rl_agents/onnx/csharp/docs/SessionConfigurator.xml +29 -0
  12. addons/godot_rl_agents/onnx/wrapper/ONNX_wrapper.gd +24 -0
  13. addons/godot_rl_agents/plugin.cfg +7 -0
  14. addons/godot_rl_agents/sensors/sensors_2d/ExampleRaycastSensor2D.tscn +48 -0
  15. addons/godot_rl_agents/sensors/sensors_2d/ISensor2D.gd +20 -0
  16. addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.gd +118 -0
  17. addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.tscn +7 -0
  18. addons/godot_rl_agents/sensors/sensors_3d/ExampleRaycastSensor3D.tscn +6 -0
  19. addons/godot_rl_agents/sensors/sensors_3d/ISensor3D.gd +20 -0
  20. addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.gd +11 -0
  21. addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.tscn +42 -0
  22. addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.gd +166 -0
  23. addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.tscn +33 -0
  24. addons/godot_rl_agents/sync.gd +345 -0
  25. asset-license.md +5 -0
  26. blender/.gitignore +2 -0
  27. blender/lander.blend +0 -0
  28. blender/lander.blend.import +50 -0
  29. blender/landing-leg.blend +0 -0
  30. blender/landing-leg.blend.import +50 -0
  31. icon.svg +1 -0
  32. onnx/model.onnx +3 -0
  33. project.godot +66 -0
  34. readme.md +151 -0
  35. scenes/game_scene/CameraFollowLander.gd +19 -0
  36. scenes/game_scene/Lander.gd +329 -0
  37. scenes/game_scene/Lander.tscn +871 -0
  38. scenes/game_scene/LanderAIController3D.gd +108 -0
  39. scenes/game_scene/Terrain.gd +169 -0
  40. scenes/game_scene/Thruster.gd +22 -0
  41. scenes/game_scene/game_scene.tscn +0 -0
  42. scenes/testing_scene/manual_test_scene.tscn +0 -0
  43. scenes/testing_scene/testing_scene.tscn +0 -0
  44. scenes/training_scene/SyncAddControlModeSelection.gd +36 -0
  45. scenes/training_scene/training_scene.tscn +61 -0
README.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: godot-rl
3
+ tags:
4
+ - deep-reinforcement-learning
5
+ - reinforcement-learning
6
+ - godot-rl
7
+ - environments
8
+ - video-games
9
+ ---
10
+
11
+ A RL environment called 3DLander for the Godot Game Engine.
12
+
13
+ This environment was created with: https://github.com/edbeeching/godot_rl_agents
14
+
15
+
16
+ ## Downloading the environment
17
+
18
+ After installing Godot RL Agents, download the environment with:
19
+
20
+ ```
21
+ gdrl.env_from_hub -r jtatman/godot_rl_3DLander
22
+ ```
23
+
24
+
25
+
Spaceship.csproj ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <Project Sdk="Godot.NET.Sdk/4.2.0">
2
+ <PropertyGroup>
3
+ <TargetFramework>net6.0</TargetFramework>
4
+ <EnableDynamicLoading>true</EnableDynamicLoading>
5
+ <RootNamespace>GodotRLAgents</RootNamespace>
6
+ </PropertyGroup>
7
+ <ItemGroup>
8
+ <PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.16.3" />
9
+ </ItemGroup>
10
+ </Project>
Spaceship.sln ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Microsoft Visual Studio Solution File, Format Version 12.00
2
+ # Visual Studio 2012
3
+ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spaceship", "Spaceship.csproj", "{DC46F402-2A25-4B5F-8C88-0709BA297354}"
4
+ EndProject
5
+ Global
6
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
7
+ Debug|Any CPU = Debug|Any CPU
8
+ ExportDebug|Any CPU = ExportDebug|Any CPU
9
+ ExportRelease|Any CPU = ExportRelease|Any CPU
10
+ EndGlobalSection
11
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
12
+ {DC46F402-2A25-4B5F-8C88-0709BA297354}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13
+ {DC46F402-2A25-4B5F-8C88-0709BA297354}.Debug|Any CPU.Build.0 = Debug|Any CPU
14
+ {DC46F402-2A25-4B5F-8C88-0709BA297354}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
15
+ {DC46F402-2A25-4B5F-8C88-0709BA297354}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
16
+ {DC46F402-2A25-4B5F-8C88-0709BA297354}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
17
+ {DC46F402-2A25-4B5F-8C88-0709BA297354}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
18
+ EndGlobalSection
19
+ EndGlobal
addons/godot_rl_agents/controller/ai_controller_2d.gd ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node2D
2
+ class_name AIController2D
3
+
4
+ @export var reset_after := 1000
5
+
6
+ var heuristic := "human"
7
+ var done := false
8
+ var reward := 0.0
9
+ var n_steps := 0
10
+ var needs_reset := false
11
+
12
+ var _player: Node2D
13
+
14
+ func _ready():
15
+ add_to_group("AGENT")
16
+
17
+ func init(player: Node2D):
18
+ _player = player
19
+
20
+ #-- Methods that need implementing using the "extend script" option in Godot --#
21
+ func get_obs() -> Dictionary:
22
+ assert(false, "the get_obs method is not implemented when extending from ai_controller")
23
+ return {"obs":[]}
24
+
25
+ func get_reward() -> float:
26
+ assert(false, "the get_reward method is not implemented when extending from ai_controller")
27
+ return 0.0
28
+
29
+ func get_action_space() -> Dictionary:
30
+ assert(false, "the get get_action_space method is not implemented when extending from ai_controller")
31
+ return {
32
+ "example_actions_continous" : {
33
+ "size": 2,
34
+ "action_type": "continuous"
35
+ },
36
+ "example_actions_discrete" : {
37
+ "size": 2,
38
+ "action_type": "discrete"
39
+ },
40
+ }
41
+
42
+ func set_action(action) -> void:
43
+ assert(false, "the get set_action method is not implemented when extending from ai_controller")
44
+ # -----------------------------------------------------------------------------#
45
+
46
+ func _physics_process(delta):
47
+ n_steps += 1
48
+ if n_steps > reset_after:
49
+ needs_reset = true
50
+
51
+ func get_obs_space():
52
+ # may need overriding if the obs space is complex
53
+ var obs = get_obs()
54
+ return {
55
+ "obs": {
56
+ "size": [len(obs["obs"])],
57
+ "space": "box"
58
+ },
59
+ }
60
+
61
+ func reset():
62
+ n_steps = 0
63
+ needs_reset = false
64
+
65
+ func reset_if_done():
66
+ if done:
67
+ reset()
68
+
69
+ func set_heuristic(h):
70
+ # sets the heuristic from "human" or "model" nothing to change here
71
+ heuristic = h
72
+
73
+ func get_done():
74
+ return done
75
+
76
+ func set_done_false():
77
+ done = false
78
+
79
+ func zero_reward():
80
+ reward = 0.0
81
+
82
+
addons/godot_rl_agents/controller/ai_controller_3d.gd ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node3D
2
+ class_name AIController3D
3
+
4
+ @export var reset_after := 1000
5
+
6
+ var heuristic := "human"
7
+ var done := false
8
+ var reward := 0.0
9
+ var n_steps := 0
10
+ var needs_reset := false
11
+
12
+ var _player: Node3D
13
+
14
+ func _ready():
15
+ add_to_group("AGENT")
16
+
17
+ func init(player: Node3D):
18
+ _player = player
19
+
20
+ #-- Methods that need implementing using the "extend script" option in Godot --#
21
+ func get_obs() -> Dictionary:
22
+ assert(false, "the get_obs method is not implemented when extending from ai_controller")
23
+ return {"obs":[]}
24
+
25
+ func get_reward() -> float:
26
+ assert(false, "the get_reward method is not implemented when extending from ai_controller")
27
+ return 0.0
28
+
29
+ func get_action_space() -> Dictionary:
30
+ assert(false, "the get get_action_space method is not implemented when extending from ai_controller")
31
+ return {
32
+ "example_actions_continous" : {
33
+ "size": 2,
34
+ "action_type": "continuous"
35
+ },
36
+ "example_actions_discrete" : {
37
+ "size": 2,
38
+ "action_type": "discrete"
39
+ },
40
+ }
41
+
42
+ func set_action(action) -> void:
43
+ assert(false, "the get set_action method is not implemented when extending from ai_controller")
44
+ # -----------------------------------------------------------------------------#
45
+
46
+ func _physics_process(delta):
47
+ n_steps += 1
48
+ if n_steps > reset_after:
49
+ needs_reset = true
50
+
51
+ func get_obs_space():
52
+ # may need overriding if the obs space is complex
53
+ var obs = get_obs()
54
+ return {
55
+ "obs": {
56
+ "size": [len(obs["obs"])],
57
+ "space": "box"
58
+ },
59
+ }
60
+
61
+ func reset():
62
+ n_steps = 0
63
+ needs_reset = false
64
+
65
+ func reset_if_done():
66
+ if done:
67
+ reset()
68
+
69
+ func set_heuristic(h):
70
+ # sets the heuristic from "human" or "model" nothing to change here
71
+ heuristic = h
72
+
73
+ func get_done():
74
+ return done
75
+
76
+ func set_done_false():
77
+ done = false
78
+
79
+ func zero_reward():
80
+ reward = 0.0
addons/godot_rl_agents/godot_rl_agents.gd ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends EditorPlugin
3
+
4
+
5
+ func _enter_tree():
6
+ # Initialization of the plugin goes here.
7
+ # Add the new type with a name, a parent type, a script and an icon.
8
+ add_custom_type("Sync", "Node", preload("sync.gd"), preload("icon.png"))
9
+ #add_custom_type("RaycastSensor2D2", "Node", preload("raycast_sensor_2d.gd"), preload("icon.png"))
10
+
11
+
12
+ func _exit_tree():
13
+ # Clean-up of the plugin goes here.
14
+ # Always remember to remove it from the engine when deactivated.
15
+ remove_custom_type("Sync")
16
+ #remove_custom_type("RaycastSensor2D2")
addons/godot_rl_agents/icon.png ADDED

Git LFS Details

  • SHA256: e3a8bc372d3313ce1ede4e7554472e37b322178b9488bfb709e296585abd3c44
  • Pointer size: 128 Bytes
  • Size of remote file: 198 Bytes
addons/godot_rl_agents/onnx/csharp/ONNXInference.cs ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Godot;
2
+ using Microsoft.ML.OnnxRuntime;
3
+ using Microsoft.ML.OnnxRuntime.Tensors;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+
7
+ namespace GodotONNX
8
+ {
9
+ /// <include file='docs/ONNXInference.xml' path='docs/members[@name="ONNXInference"]/ONNXInference/*'/>
10
+ public partial class ONNXInference : GodotObject
11
+ {
12
+
13
+ private InferenceSession session;
14
+ /// <summary>
15
+ /// Path to the ONNX model. Use Initialize to change it.
16
+ /// </summary>
17
+ private string modelPath;
18
+ private int batchSize;
19
+
20
+ private SessionOptions SessionOpt;
21
+
22
+ //init function
23
+ /// <include file='docs/ONNXInference.xml' path='docs/members[@name="ONNXInference"]/Initialize/*'/>
24
+ public void Initialize(string Path, int BatchSize)
25
+ {
26
+ modelPath = Path;
27
+ batchSize = BatchSize;
28
+ SessionOpt = SessionConfigurator.MakeConfiguredSessionOptions();
29
+ session = LoadModel(modelPath);
30
+
31
+ }
32
+ /// <include file='docs/ONNXInference.xml' path='docs/members[@name="ONNXInference"]/Run/*'/>
33
+ public Godot.Collections.Dictionary<string, Godot.Collections.Array> RunInference(Godot.Collections.Array<float> obs, int state_ins)
34
+ {
35
+ //Current model: Any (Godot Rl Agents)
36
+ //Expects a tensor of shape [batch_size, input_size] type float named obs and a tensor of shape [batch_size] type float named state_ins
37
+
38
+ //Fill the input tensors
39
+ // create span from inputSize
40
+ var span = new float[obs.Count]; //There's probably a better way to do this
41
+ for (int i = 0; i < obs.Count; i++)
42
+ {
43
+ span[i] = obs[i];
44
+ }
45
+
46
+ IReadOnlyCollection<NamedOnnxValue> inputs = new List<NamedOnnxValue>
47
+ {
48
+ NamedOnnxValue.CreateFromTensor("obs", new DenseTensor<float>(span, new int[] { batchSize, obs.Count })),
49
+ NamedOnnxValue.CreateFromTensor("state_ins", new DenseTensor<float>(new float[] { state_ins }, new int[] { batchSize }))
50
+ };
51
+ IReadOnlyCollection<string> outputNames = new List<string> { "output", "state_outs" }; //ONNX is sensible to these names, as well as the input names
52
+
53
+ IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results;
54
+ //We do not use "using" here so we get a better exception explaination later
55
+ try
56
+ {
57
+ results = session.Run(inputs, outputNames);
58
+ }
59
+ catch (OnnxRuntimeException e)
60
+ {
61
+ //This error usually means that the model is not compatible with the input, beacause of the input shape (size)
62
+ GD.Print("Error at inference: ", e);
63
+ return null;
64
+ }
65
+ //Can't convert IEnumerable<float> to Variant, so we have to convert it to an array or something
66
+ Godot.Collections.Dictionary<string, Godot.Collections.Array> output = new();
67
+ DisposableNamedOnnxValue output1 = results.First();
68
+ DisposableNamedOnnxValue output2 = results.Last();
69
+
70
+ // Output1 array may contains longs if only discrete actions are used or floats otherwise
71
+ Godot.Collections.Array output1Array = new();
72
+ Godot.Collections.Array output2Array = new();
73
+
74
+ // SB3 exported model will send float actions if continuous actions are used in the environment
75
+ // (also the case with mixed actions)
76
+ if (output1.ElementType == TensorElementType.Float)
77
+ {
78
+ foreach (float f in output1.AsEnumerable<float>())
79
+ {
80
+ output1Array.Add(f);
81
+ }
82
+ }
83
+ // SB3 exported model will send int64 actions if only discrete actions are used in the environment
84
+ else if (output1.ElementType == TensorElementType.Int64)
85
+ {
86
+ foreach (long l in output1.AsEnumerable<long>())
87
+ {
88
+ output1Array.Add(l);
89
+ }
90
+ }
91
+
92
+ foreach (float f in output2.AsEnumerable<float>())
93
+ {
94
+ output2Array.Add(f);
95
+ }
96
+
97
+ output.Add(output1.Name, output1Array);
98
+ output.Add(output2.Name, output2Array);
99
+
100
+ //Output is a dictionary of arrays, ex: { "output" : [0.1, 0.2, 0.3, 0.4, ...], "state_outs" : [0.5, ...]}
101
+ results.Dispose();
102
+ return output;
103
+ }
104
+ /// <include file='docs/ONNXInference.xml' path='docs/members[@name="ONNXInference"]/Load/*'/>
105
+ public InferenceSession LoadModel(string Path)
106
+ {
107
+ using FileAccess file = FileAccess.Open(Path, FileAccess.ModeFlags.Read);
108
+ byte[] model = file.GetBuffer((int)file.GetLength());
109
+ //file.Close(); file.Dispose(); //Close the file, then dispose the reference.
110
+ return new InferenceSession(model, SessionOpt); //Load the model
111
+ }
112
+ public void FreeDisposables()
113
+ {
114
+ session.Dispose();
115
+ SessionOpt.Dispose();
116
+ }
117
+ }
118
+ }
addons/godot_rl_agents/onnx/csharp/SessionConfigurator.cs ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Godot;
2
+ using Microsoft.ML.OnnxRuntime;
3
+
4
+ namespace GodotONNX
5
+ {
6
+ /// <include file='docs/SessionConfigurator.xml' path='docs/members[@name="SessionConfigurator"]/SessionConfigurator/*'/>
7
+
8
+ public static class SessionConfigurator
9
+ {
10
+ public enum ComputeName
11
+ {
12
+ CUDA,
13
+ ROCm,
14
+ DirectML,
15
+ CoreML,
16
+ CPU
17
+ }
18
+
19
+ /// <include file='docs/SessionConfigurator.xml' path='docs/members[@name="SessionConfigurator"]/GetSessionOptions/*'/>
20
+ public static SessionOptions MakeConfiguredSessionOptions()
21
+ {
22
+ SessionOptions sessionOptions = new();
23
+ SetOptions(sessionOptions);
24
+ return sessionOptions;
25
+ }
26
+
27
+ private static void SetOptions(SessionOptions sessionOptions)
28
+ {
29
+ sessionOptions.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_WARNING;
30
+ ApplySystemSpecificOptions(sessionOptions);
31
+ }
32
+
33
+ /// <include file='docs/SessionConfigurator.xml' path='docs/members[@name="SessionConfigurator"]/SystemCheck/*'/>
34
+ static public void ApplySystemSpecificOptions(SessionOptions sessionOptions)
35
+ {
36
+ //Most code for this function is verbose only, the only reason it exists is to track
37
+ //implementation progress of the different compute APIs.
38
+
39
+ //December 2022: CUDA is not working.
40
+
41
+ string OSName = OS.GetName(); //Get OS Name
42
+
43
+ //ComputeName ComputeAPI = ComputeCheck(); //Get Compute API
44
+ // //TODO: Get CPU architecture
45
+
46
+ //Linux can use OpenVINO (C#) on x64 and ROCm on x86 (GDNative/C++)
47
+ //Windows can use OpenVINO (C#) on x64
48
+ //TODO: try TensorRT instead of CUDA
49
+ //TODO: Use OpenVINO for Intel Graphics
50
+
51
+ // Temporarily using CPU on all platforms to avoid errors detected with DML
52
+ ComputeName ComputeAPI = ComputeName.CPU;
53
+
54
+ //match OS and Compute API
55
+ GD.Print($"OS: {OSName} Compute API: {ComputeAPI}");
56
+
57
+ // CPU is set by default without appending necessary
58
+ // sessionOptions.AppendExecutionProvider_CPU(0);
59
+
60
+ /*
61
+ switch (OSName)
62
+ {
63
+ case "Windows": //Can use CUDA, DirectML
64
+ if (ComputeAPI is ComputeName.CUDA)
65
+ {
66
+ //CUDA
67
+ //sessionOptions.AppendExecutionProvider_CUDA(0);
68
+ //sessionOptions.AppendExecutionProvider_DML(0);
69
+ }
70
+ else if (ComputeAPI is ComputeName.DirectML)
71
+ {
72
+ //DirectML
73
+ //sessionOptions.AppendExecutionProvider_DML(0);
74
+ }
75
+ break;
76
+ case "X11": //Can use CUDA, ROCm
77
+ if (ComputeAPI is ComputeName.CUDA)
78
+ {
79
+ //CUDA
80
+ //sessionOptions.AppendExecutionProvider_CUDA(0);
81
+ }
82
+ if (ComputeAPI is ComputeName.ROCm)
83
+ {
84
+ //ROCm, only works on x86
85
+ //Research indicates that this has to be compiled as a GDNative plugin
86
+ //GD.Print("ROCm not supported yet, using CPU.");
87
+ //sessionOptions.AppendExecutionProvider_CPU(0);
88
+ }
89
+ break;
90
+ case "macOS": //Can use CoreML
91
+ if (ComputeAPI is ComputeName.CoreML)
92
+ { //CoreML
93
+ //TODO: Needs testing
94
+ //sessionOptions.AppendExecutionProvider_CoreML(0);
95
+ //CoreML on ARM64, out of the box, on x64 needs .tar file from GitHub
96
+ }
97
+ break;
98
+ default:
99
+ GD.Print("OS not Supported.");
100
+ break;
101
+ }
102
+ */
103
+ }
104
+
105
+
106
+ /// <include file='docs/SessionConfigurator.xml' path='docs/members[@name="SessionConfigurator"]/ComputeCheck/*'/>
107
+ public static ComputeName ComputeCheck()
108
+ {
109
+ string adapterName = Godot.RenderingServer.GetVideoAdapterName();
110
+ //string adapterVendor = Godot.RenderingServer.GetVideoAdapterVendor();
111
+ adapterName = adapterName.ToUpper(new System.Globalization.CultureInfo(""));
112
+ //TODO: GPU vendors for MacOS, what do they even use these days?
113
+
114
+ if (adapterName.Contains("INTEL"))
115
+ {
116
+ return ComputeName.DirectML;
117
+ }
118
+ if (adapterName.Contains("AMD") || adapterName.Contains("RADEON"))
119
+ {
120
+ return ComputeName.DirectML;
121
+ }
122
+ if (adapterName.Contains("NVIDIA"))
123
+ {
124
+ return ComputeName.CUDA;
125
+ }
126
+
127
+ GD.Print("Graphics Card not recognized."); //Should use CPU
128
+ return ComputeName.CPU;
129
+ }
130
+ }
131
+ }
addons/godot_rl_agents/onnx/csharp/docs/ONNXInference.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <docs>
2
+ <members name="ONNXInference">
3
+ <ONNXInference>
4
+ <summary>
5
+ The main <c>ONNXInference</c> Class that handles the inference process.
6
+ </summary>
7
+ </ONNXInference>
8
+ <Initialize>
9
+ <summary>
10
+ Starts the inference process.
11
+ </summary>
12
+ <param name="Path">Path to the ONNX model, expects a path inside resources.</param>
13
+ <param name="BatchSize">How many observations will the model recieve.</param>
14
+ </Initialize>
15
+ <Run>
16
+ <summary>
17
+ Runs the given input through the model and returns the output.
18
+ </summary>
19
+ <param name="obs">Dictionary containing all observations.</param>
20
+ <param name="state_ins">How many different agents are creating these observations.</param>
21
+ <returns>A Dictionary of arrays, containing instructions based on the observations. Arrays can hold either C# longs for discrete-only action space, or C# floats. </returns>
22
+ </Run>
23
+ <Load>
24
+ <summary>
25
+ Loads the given model into the inference process, using the best Execution provider available.
26
+ </summary>
27
+ <param name="Path">Path to the ONNX model, expects a path inside resources.</param>
28
+ <returns>InferenceSession ready to run.</returns>
29
+ </Load>
30
+ </members>
31
+ </docs>
addons/godot_rl_agents/onnx/csharp/docs/SessionConfigurator.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <docs>
2
+ <members name="SessionConfigurator">
3
+ <SessionConfigurator>
4
+ <summary>
5
+ The main <c>SessionConfigurator</c> Class that handles the execution options and providers for the inference process.
6
+ </summary>
7
+ </SessionConfigurator>
8
+ <GetSessionOptions>
9
+ <summary>
10
+ Creates a SessionOptions with all available execution providers.
11
+ </summary>
12
+ <returns>SessionOptions with all available execution providers.</returns>
13
+ </GetSessionOptions>
14
+ <SystemCheck>
15
+ <summary>
16
+ Appends any execution provider available in the current system.
17
+ </summary>
18
+ <remarks>
19
+ This function is mainly verbose for tracking implementation progress of different compute APIs.
20
+ </remarks>
21
+ </SystemCheck>
22
+ <ComputeCheck>
23
+ <summary>
24
+ Checks for available GPUs.
25
+ </summary>
26
+ <returns>An integer identifier for each compute platform.</returns>
27
+ </ComputeCheck>
28
+ </members>
29
+ </docs>
addons/godot_rl_agents/onnx/wrapper/ONNX_wrapper.gd ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Resource
2
+ class_name ONNXModel
3
+ var inferencer_script = load("res://addons/godot_rl_agents/onnx/csharp/ONNXInference.cs")
4
+
5
+ var inferencer = null
6
+
7
+ # Must provide the path to the model and the batch size
8
+ func _init(model_path, batch_size):
9
+ inferencer = inferencer_script.new()
10
+ inferencer.Initialize(model_path, batch_size)
11
+
12
+ # This function is the one that will be called from the game,
13
+ # requires the observation as an array and the state_ins as an int
14
+ # returns an Array containing the action the model takes.
15
+ func run_inference(obs : Array, state_ins : int) -> Dictionary:
16
+ if inferencer == null:
17
+ printerr("Inferencer not initialized")
18
+ return {}
19
+ return inferencer.RunInference(obs, state_ins)
20
+
21
+ func _notification(what):
22
+ if what == NOTIFICATION_PREDELETE:
23
+ inferencer.FreeDisposables()
24
+ inferencer.free()
addons/godot_rl_agents/plugin.cfg ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [plugin]
2
+
3
+ name="GodotRLAgents"
4
+ description="Custom nodes for the godot rl agents toolkit "
5
+ author="Edward Beeching"
6
+ version="0.1"
7
+ script="godot_rl_agents.gd"
addons/godot_rl_agents/sensors/sensors_2d/ExampleRaycastSensor2D.tscn ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=5 format=3 uid="uid://ddeq7mn1ealyc"]
2
+
3
+ [ext_resource type="Script" path="res://addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.gd" id="1"]
4
+
5
+ [sub_resource type="GDScript" id="2"]
6
+ script/source = "extends Node2D
7
+
8
+
9
+
10
+ func _physics_process(delta: float) -> void:
11
+ print(\"step start\")
12
+
13
+ "
14
+
15
+ [sub_resource type="GDScript" id="1"]
16
+ script/source = "extends RayCast2D
17
+
18
+ var steps = 1
19
+
20
+ func _physics_process(delta: float) -> void:
21
+ print(\"processing raycast\")
22
+ steps += 1
23
+ if steps % 2:
24
+ force_raycast_update()
25
+
26
+ print(is_colliding())
27
+ "
28
+
29
+ [sub_resource type="CircleShape2D" id="3"]
30
+
31
+ [node name="ExampleRaycastSensor2D" type="Node2D"]
32
+ script = SubResource("2")
33
+
34
+ [node name="ExampleAgent" type="Node2D" parent="."]
35
+ position = Vector2(573, 314)
36
+ rotation = 0.286234
37
+
38
+ [node name="RaycastSensor2D" type="Node2D" parent="ExampleAgent"]
39
+ script = ExtResource("1")
40
+
41
+ [node name="TestRayCast2D" type="RayCast2D" parent="."]
42
+ script = SubResource("1")
43
+
44
+ [node name="StaticBody2D" type="StaticBody2D" parent="."]
45
+ position = Vector2(1, 52)
46
+
47
+ [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
48
+ shape = SubResource("3")
addons/godot_rl_agents/sensors/sensors_2d/ISensor2D.gd ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node2D
2
+ class_name ISensor2D
3
+
4
+ var _obs : Array = []
5
+ var _active := false
6
+
7
+ func get_observation():
8
+ pass
9
+
10
+ func activate():
11
+ _active = true
12
+
13
+ func deactivate():
14
+ _active = false
15
+
16
+ func _update_observation():
17
+ pass
18
+
19
+ func reset():
20
+ pass
addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.gd ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends ISensor2D
3
+ class_name RaycastSensor2D
4
+
5
+ @export_flags_2d_physics var collision_mask := 1:
6
+ get: return collision_mask
7
+ set(value):
8
+ collision_mask = value
9
+ _update()
10
+
11
+ @export var collide_with_areas := false:
12
+ get: return collide_with_areas
13
+ set(value):
14
+ collide_with_areas = value
15
+ _update()
16
+
17
+ @export var collide_with_bodies := true:
18
+ get: return collide_with_bodies
19
+ set(value):
20
+ collide_with_bodies = value
21
+ _update()
22
+
23
+ @export var n_rays := 16.0:
24
+ get: return n_rays
25
+ set(value):
26
+ n_rays = value
27
+ _update()
28
+
29
+ @export_range(5,200,5.0) var ray_length := 200:
30
+ get: return ray_length
31
+ set(value):
32
+ ray_length = value
33
+ _update()
34
+ @export_range(5,360,5.0) var cone_width := 360.0:
35
+ get: return cone_width
36
+ set(value):
37
+ cone_width = value
38
+ _update()
39
+
40
+ @export var debug_draw := true :
41
+ get: return debug_draw
42
+ set(value):
43
+ debug_draw = value
44
+ _update()
45
+
46
+
47
+ var _angles = []
48
+ var rays := []
49
+
50
+ func _update():
51
+ if Engine.is_editor_hint():
52
+ if debug_draw:
53
+ _spawn_nodes()
54
+ else:
55
+ for ray in get_children():
56
+ if ray is RayCast2D:
57
+ remove_child(ray)
58
+
59
+ func _ready() -> void:
60
+ _spawn_nodes()
61
+
62
+ func _spawn_nodes():
63
+ for ray in rays:
64
+ ray.queue_free()
65
+ rays = []
66
+
67
+ _angles = []
68
+ var step = cone_width / (n_rays)
69
+ var start = step/2 - cone_width/2
70
+
71
+ for i in n_rays:
72
+ var angle = start + i * step
73
+ var ray = RayCast2D.new()
74
+ ray.set_target_position(Vector2(
75
+ ray_length*cos(deg_to_rad(angle)),
76
+ ray_length*sin(deg_to_rad(angle))
77
+ ))
78
+ ray.set_name("node_"+str(i))
79
+ ray.enabled = true
80
+ ray.collide_with_areas = collide_with_areas
81
+ ray.collide_with_bodies = collide_with_bodies
82
+ ray.collision_mask = collision_mask
83
+ add_child(ray)
84
+ rays.append(ray)
85
+
86
+
87
+ _angles.append(start + i * step)
88
+
89
+
90
+ func _physics_process(delta: float) -> void:
91
+ if self._active:
92
+ self._obs = calculate_raycasts()
93
+
94
+ func get_observation() -> Array:
95
+ if len(self._obs) == 0:
96
+ print("obs was null, forcing raycast update")
97
+ return self.calculate_raycasts()
98
+ return self._obs
99
+
100
+
101
+ func calculate_raycasts() -> Array:
102
+ var result = []
103
+ for ray in rays:
104
+ ray.force_raycast_update()
105
+ var distance = _get_raycast_distance(ray)
106
+ result.append(distance)
107
+ return result
108
+
109
+ func _get_raycast_distance(ray : RayCast2D) -> float :
110
+ if !ray.is_colliding():
111
+ return 0.0
112
+
113
+ var distance = (global_position - ray.get_collision_point()).length()
114
+ distance = clamp(distance, 0.0, ray_length)
115
+ return (ray_length - distance) / ray_length
116
+
117
+
118
+
addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.tscn ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=2 format=3 uid="uid://drvfihk5esgmv"]
2
+
3
+ [ext_resource type="Script" path="res://addons/godot_rl_agents/sensors/sensors_2d/RaycastSensor2D.gd" id="1"]
4
+
5
+ [node name="RaycastSensor2D" type="Node2D"]
6
+ script = ExtResource("1")
7
+ n_rays = 17.0
addons/godot_rl_agents/sensors/sensors_3d/ExampleRaycastSensor3D.tscn ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [gd_scene format=3 uid="uid://biu787qh4woik"]
2
+
3
+ [node name="ExampleRaycastSensor3D" type="Node3D"]
4
+
5
+ [node name="Camera3D" type="Camera3D" parent="."]
6
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.804183, 0, 2.70146)
addons/godot_rl_agents/sensors/sensors_3d/ISensor3D.gd ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node3D
2
+ class_name ISensor3D
3
+
4
+ var _obs : Array = []
5
+ var _active := false
6
+
7
+ func get_observation():
8
+ pass
9
+
10
+ func activate():
11
+ _active = true
12
+
13
+ func deactivate():
14
+ _active = false
15
+
16
+ func _update_observation():
17
+ pass
18
+
19
+ func reset():
20
+ pass
addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.gd ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node3D
2
+ class_name RGBCameraSensor3D
3
+ var camera_pixels = null
4
+
5
+ @onready var camera_texture := $Control/TextureRect/CameraTexture as Sprite2D
6
+
7
+ func get_camera_pixel_encoding():
8
+ return camera_texture.get_texture().get_image().data["data"].hex_encode()
9
+
10
+ func get_camera_shape()-> Array:
11
+ return [$SubViewport.size[0], $SubViewport.size[1], 4]
addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.tscn ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=3 format=2]
2
+
3
+ [ext_resource path="res://addons/godot_rl_agents/sensors/sensors_3d/RGBCameraSensor3D.gd" type="Script" id=1]
4
+
5
+ [sub_resource type="ViewportTexture" id=1]
6
+ viewport_path = NodePath("SubViewport")
7
+
8
+ [node name="RGBCameraSensor3D" type="Node3D"]
9
+ script = ExtResource( 1 )
10
+
11
+ [node name="RemoteTransform3D" type="RemoteTransform3D" parent="."]
12
+ remote_path = NodePath("../SubViewport/Camera3D")
13
+
14
+ [node name="SubViewport" type="SubViewport" parent="."]
15
+ size = Vector2( 32, 32 )
16
+ render_target_update_mode = 3
17
+
18
+ [node name="Camera3D" type="Camera3D" parent="SubViewport"]
19
+ near = 0.5
20
+
21
+ [node name="Control" type="Control" parent="."]
22
+ anchor_right = 1.0
23
+ anchor_bottom = 1.0
24
+ __meta__ = {
25
+ "_edit_use_anchors_": false
26
+ }
27
+
28
+ [node name="TextureRect" type="ColorRect" parent="Control"]
29
+ offset_left = 1096.0
30
+ offset_top = 534.0
31
+ offset_right = 1114.0
32
+ offset_bottom = 552.0
33
+ scale = Vector2( 10, 10 )
34
+ color = Color( 0.00784314, 0.00784314, 0.00784314, 1 )
35
+ __meta__ = {
36
+ "_edit_use_anchors_": false
37
+ }
38
+
39
+ [node name="CameraTexture" type="Sprite2D" parent="Control/TextureRect"]
40
+ texture = SubResource( 1 )
41
+ offset = Vector2( 9, 9 )
42
+ flip_v = true
addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.gd ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends ISensor3D
3
+ class_name RayCastSensor3D
4
+ @export_flags_3d_physics var collision_mask = 1:
5
+ get: return collision_mask
6
+ set(value):
7
+ collision_mask = value
8
+ _update()
9
+ @export_flags_3d_physics var boolean_class_mask = 1:
10
+ get: return boolean_class_mask
11
+ set(value):
12
+ boolean_class_mask = value
13
+ _update()
14
+
15
+ @export var n_rays_width := 6.0:
16
+ get: return n_rays_width
17
+ set(value):
18
+ n_rays_width = value
19
+ _update()
20
+
21
+ @export var n_rays_height := 6.0:
22
+ get: return n_rays_height
23
+ set(value):
24
+ n_rays_height = value
25
+ _update()
26
+
27
+ @export var ray_length := 10.0:
28
+ get: return ray_length
29
+ set(value):
30
+ ray_length = value
31
+ _update()
32
+
33
+ @export var cone_width := 60.0:
34
+ get: return cone_width
35
+ set(value):
36
+ cone_width = value
37
+ _update()
38
+
39
+ @export var cone_height := 60.0:
40
+ get: return cone_height
41
+ set(value):
42
+ cone_height = value
43
+ _update()
44
+
45
+ @export var collide_with_areas := false:
46
+ get: return collide_with_areas
47
+ set(value):
48
+ collide_with_areas = value
49
+ _update()
50
+
51
+ @export var collide_with_bodies := true:
52
+ get: return collide_with_bodies
53
+ set(value):
54
+ collide_with_bodies = value
55
+ _update()
56
+
57
+ @export var class_sensor := false
58
+
59
+ var rays := []
60
+ var geo = null
61
+
62
+ func _update():
63
+ if Engine.is_editor_hint():
64
+ if is_node_ready():
65
+ _spawn_nodes()
66
+
67
+ func _ready() -> void:
68
+ if Engine.is_editor_hint():
69
+ if get_child_count() == 0:
70
+ _spawn_nodes()
71
+ else:
72
+ _spawn_nodes()
73
+
74
+ func _spawn_nodes():
75
+ print("spawning nodes")
76
+ for ray in get_children():
77
+ ray.queue_free()
78
+ if geo:
79
+ geo.clear()
80
+ #$Lines.remove_points()
81
+ rays = []
82
+
83
+ var horizontal_step = cone_width / (n_rays_width)
84
+ var vertical_step = cone_height / (n_rays_height)
85
+
86
+ var horizontal_start = horizontal_step/2 - cone_width/2
87
+ var vertical_start = vertical_step/2 - cone_height/2
88
+
89
+ var points = []
90
+
91
+ for i in n_rays_width:
92
+ for j in n_rays_height:
93
+ var angle_w = horizontal_start + i * horizontal_step
94
+ var angle_h = vertical_start + j * vertical_step
95
+ #angle_h = 0.0
96
+ var ray = RayCast3D.new()
97
+ var cast_to = to_spherical_coords(ray_length, angle_w, angle_h)
98
+ ray.set_target_position(cast_to)
99
+
100
+ points.append(cast_to)
101
+
102
+ ray.set_name("node_"+str(i)+" "+str(j))
103
+ ray.enabled = true
104
+ ray.collide_with_bodies = collide_with_bodies
105
+ ray.collide_with_areas = collide_with_areas
106
+ ray.collision_mask = collision_mask
107
+ add_child(ray)
108
+ ray.set_owner(get_tree().edited_scene_root)
109
+ rays.append(ray)
110
+ ray.force_raycast_update()
111
+
112
+ # if Engine.editor_hint:
113
+ # _create_debug_lines(points)
114
+
115
+ func _create_debug_lines(points):
116
+ if not geo:
117
+ geo = ImmediateMesh.new()
118
+ add_child(geo)
119
+
120
+ geo.clear()
121
+ geo.begin(Mesh.PRIMITIVE_LINES)
122
+ for point in points:
123
+ geo.set_color(Color.AQUA)
124
+ geo.add_vertex(Vector3.ZERO)
125
+ geo.add_vertex(point)
126
+ geo.end()
127
+
128
+ func display():
129
+ if geo:
130
+ geo.display()
131
+
132
+ func to_spherical_coords(r, inc, azimuth) -> Vector3:
133
+ return Vector3(
134
+ r*sin(deg_to_rad(inc))*cos(deg_to_rad(azimuth)),
135
+ r*sin(deg_to_rad(azimuth)),
136
+ r*cos(deg_to_rad(inc))*cos(deg_to_rad(azimuth))
137
+ )
138
+
139
+ func get_observation() -> Array:
140
+ return self.calculate_raycasts()
141
+
142
+ func calculate_raycasts() -> Array:
143
+ var result = []
144
+ for ray in rays:
145
+ ray.set_enabled(true)
146
+ ray.force_raycast_update()
147
+ var distance = _get_raycast_distance(ray)
148
+
149
+ result.append(distance)
150
+ if class_sensor:
151
+ var hit_class = 0
152
+ if ray.get_collider():
153
+ var hit_collision_layer = ray.get_collider().collision_layer
154
+ hit_collision_layer = hit_collision_layer & collision_mask
155
+ hit_class = (hit_collision_layer & boolean_class_mask) > 0
156
+ result.append(hit_class)
157
+ ray.set_enabled(false)
158
+ return result
159
+
160
+ func _get_raycast_distance(ray : RayCast3D) -> float :
161
+ if !ray.is_colliding():
162
+ return 0.0
163
+
164
+ var distance = (global_transform.origin - ray.get_collision_point()).length()
165
+ distance = clamp(distance, 0.0, ray_length)
166
+ return (ray_length - distance) / ray_length
addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.tscn ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=2 format=3 uid="uid://b803cbh1fmy66"]
2
+
3
+ [ext_resource type="Script" path="res://addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.gd" id="1"]
4
+
5
+ [node name="RaycastSensor3D" type="Node3D"]
6
+ script = ExtResource("1")
7
+ n_rays_width = 4.0
8
+ n_rays_height = 2.0
9
+ ray_length = 11.0
10
+
11
+ [node name="@node_0 0@18991" type="RayCast3D" parent="."]
12
+ target_position = Vector3(-4.06608, -2.84701, 9.81639)
13
+
14
+ [node name="node_0 1" type="RayCast3D" parent="."]
15
+ target_position = Vector3(-4.06608, 2.84701, 9.81639)
16
+
17
+ [node name="@node_1 0@18992" type="RayCast3D" parent="."]
18
+ target_position = Vector3(-1.38686, -2.84701, 10.5343)
19
+
20
+ [node name="@node_1 1@18993" type="RayCast3D" parent="."]
21
+ target_position = Vector3(-1.38686, 2.84701, 10.5343)
22
+
23
+ [node name="@node_2 0@18994" type="RayCast3D" parent="."]
24
+ target_position = Vector3(1.38686, -2.84701, 10.5343)
25
+
26
+ [node name="@node_2 1@18995" type="RayCast3D" parent="."]
27
+ target_position = Vector3(1.38686, 2.84701, 10.5343)
28
+
29
+ [node name="@node_3 0@18996" type="RayCast3D" parent="."]
30
+ target_position = Vector3(4.06608, -2.84701, 9.81639)
31
+
32
+ [node name="@node_3 1@18997" type="RayCast3D" parent="."]
33
+ target_position = Vector3(4.06608, 2.84701, 9.81639)
addons/godot_rl_agents/sync.gd ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node
2
+ # --fixed-fps 2000 --disable-render-loop
3
+ @export_range(1, 10, 1, "or_greater") var action_repeat := 8
4
+ @export_range(1, 10, 1, "or_greater") var speed_up = 1
5
+ @export var onnx_model_path := ""
6
+
7
+ @onready var start_time = Time.get_ticks_msec()
8
+
9
+ const MAJOR_VERSION := "0"
10
+ const MINOR_VERSION := "3"
11
+ const DEFAULT_PORT := "11008"
12
+ const DEFAULT_SEED := "1"
13
+ var stream : StreamPeerTCP = null
14
+ var connected = false
15
+ var message_center
16
+ var should_connect = true
17
+ var agents
18
+ var need_to_send_obs = false
19
+ var args = null
20
+ var initialized = false
21
+ var just_reset = false
22
+ var onnx_model = null
23
+ var n_action_steps = 0
24
+
25
+ var _action_space : Dictionary
26
+ var _obs_space : Dictionary
27
+
28
+ # Called when the node enters the scene tree for the first time.
29
+
30
+ func _ready():
31
+ await get_tree().root.ready
32
+ get_tree().set_pause(true)
33
+ _initialize()
34
+ await get_tree().create_timer(1.0).timeout
35
+ get_tree().set_pause(false)
36
+
37
+ func _initialize():
38
+ _get_agents()
39
+ _obs_space = agents[0].get_obs_space()
40
+ _action_space = agents[0].get_action_space()
41
+ args = _get_args()
42
+ Engine.physics_ticks_per_second = _get_speedup() * 60 # Replace with function body.
43
+ Engine.time_scale = _get_speedup() * 1.0
44
+ prints("physics ticks", Engine.physics_ticks_per_second, Engine.time_scale, _get_speedup(), speed_up)
45
+
46
+ # Run inference if onnx model path is set, otherwise wait for server connection
47
+ var run_onnx_model_inference : bool = onnx_model_path != ""
48
+ if run_onnx_model_inference:
49
+ assert(FileAccess.file_exists(onnx_model_path), "Onnx Model Path set on Sync node does not exist: " + onnx_model_path)
50
+ onnx_model = ONNXModel.new(onnx_model_path, 1)
51
+ _set_heuristic("model")
52
+ else:
53
+ connected = connect_to_server()
54
+ if connected:
55
+ _set_heuristic("model")
56
+ _handshake()
57
+ _send_env_info()
58
+ else:
59
+ _set_heuristic("human")
60
+
61
+ _set_seed()
62
+ _set_action_repeat()
63
+ initialized = true
64
+
65
+ func _physics_process(delta):
66
+ # two modes, human control, agent control
67
+ # pause tree, send obs, get actions, set actions, unpause tree
68
+ if n_action_steps % action_repeat != 0:
69
+ n_action_steps += 1
70
+ return
71
+
72
+ n_action_steps += 1
73
+
74
+ if connected:
75
+ get_tree().set_pause(true)
76
+
77
+ if just_reset:
78
+ just_reset = false
79
+ var obs = _get_obs_from_agents()
80
+
81
+ var reply = {
82
+ "type": "reset",
83
+ "obs": obs
84
+ }
85
+ _send_dict_as_json_message(reply)
86
+ # this should go straight to getting the action and setting it checked the agent, no need to perform one phyics tick
87
+ get_tree().set_pause(false)
88
+ return
89
+
90
+ if need_to_send_obs:
91
+ need_to_send_obs = false
92
+ var reward = _get_reward_from_agents()
93
+ var done = _get_done_from_agents()
94
+ #_reset_agents_if_done() # this ensures the new observation is from the next env instance : NEEDS REFACTOR
95
+
96
+ var obs = _get_obs_from_agents()
97
+
98
+ var reply = {
99
+ "type": "step",
100
+ "obs": obs,
101
+ "reward": reward,
102
+ "done": done
103
+ }
104
+ _send_dict_as_json_message(reply)
105
+
106
+ var handled = handle_message()
107
+
108
+ elif onnx_model != null:
109
+ var obs : Array = _get_obs_from_agents()
110
+
111
+ var actions = []
112
+ for o in obs:
113
+ var action = onnx_model.run_inference(o["obs"], 1.0)
114
+ var action_dict = _extract_action_dict(action["output"])
115
+ actions.append(action_dict)
116
+
117
+ _set_agent_actions(actions)
118
+ need_to_send_obs = true
119
+ get_tree().set_pause(false)
120
+ _reset_agents_if_done()
121
+
122
+ else:
123
+ _reset_agents_if_done()
124
+
125
+ func _extract_action_dict(action_array: Array):
126
+ var index = 0
127
+ var result = {}
128
+ for key in _action_space.keys():
129
+ var size = _action_space[key]["size"]
130
+ if _action_space[key]["action_type"] == "discrete":
131
+ var action = action_array[index]
132
+ # If the action received from inference is discrete, it will be received as int
133
+ # If it is a float, convert it to a binary discrete action
134
+ if (typeof(action) == TYPE_FLOAT):
135
+ result[key] = int(action > 0)
136
+ elif (typeof(action) == TYPE_INT):
137
+ result[key] = action
138
+ else:
139
+ assert(false, "Unexpected action type received, expected float or int.")
140
+ index += 1
141
+ else:
142
+ result[key] = clamp_array(action_array.slice(index,index+size), -1, 1)
143
+ index += size
144
+ return result
145
+
146
+ func _get_agents():
147
+ agents = get_tree().get_nodes_in_group("AGENT")
148
+
149
+ func _set_heuristic(heuristic):
150
+ for agent in agents:
151
+ agent.set_heuristic(heuristic)
152
+
153
+ func _handshake():
154
+ print("performing handshake")
155
+
156
+ var json_dict = _get_dict_json_message()
157
+ assert(json_dict["type"] == "handshake")
158
+ var major_version = json_dict["major_version"]
159
+ var minor_version = json_dict["minor_version"]
160
+ if major_version != MAJOR_VERSION:
161
+ print("WARNING: major verison mismatch ", major_version, " ", MAJOR_VERSION)
162
+ if minor_version != MINOR_VERSION:
163
+ print("WARNING: minor verison mismatch ", minor_version, " ", MINOR_VERSION)
164
+
165
+ print("handshake complete")
166
+
167
+ func _get_dict_json_message():
168
+ # returns a dictionary from of the most recent message
169
+ # this is not waiting
170
+ while stream.get_available_bytes() == 0:
171
+ stream.poll()
172
+ if stream.get_status() != 2:
173
+ print("server disconnected status, closing")
174
+ get_tree().quit()
175
+ return null
176
+
177
+ OS.delay_usec(10)
178
+
179
+ var message = stream.get_string()
180
+ var json_data = JSON.parse_string(message)
181
+
182
+ return json_data
183
+
184
+ func _send_dict_as_json_message(dict):
185
+ stream.put_string(JSON.stringify(dict))
186
+
187
+ func _send_env_info():
188
+ var json_dict = _get_dict_json_message()
189
+ assert(json_dict["type"] == "env_info")
190
+
191
+
192
+ var message = {
193
+ "type" : "env_info",
194
+ "observation_space": _obs_space,
195
+ "action_space":_action_space,
196
+ "n_agents": len(agents)
197
+ }
198
+ _send_dict_as_json_message(message)
199
+
200
+ func connect_to_server():
201
+ print("Waiting for one second to allow server to start")
202
+ OS.delay_msec(1000)
203
+ print("trying to connect to server")
204
+ stream = StreamPeerTCP.new()
205
+
206
+ # "localhost" was not working on windows VM, had to use the IP
207
+ var ip = "127.0.0.1"
208
+ var port = _get_port()
209
+ var connect = stream.connect_to_host(ip, port)
210
+ stream.set_no_delay(true) # TODO check if this improves performance or not
211
+ stream.poll()
212
+ # Fetch the status until it is either connected (2) or failed to connect (3)
213
+ while stream.get_status() < 2:
214
+ stream.poll()
215
+ return stream.get_status() == 2
216
+
217
+ func _get_args():
218
+ print("getting command line arguments")
219
+ var arguments = {}
220
+ for argument in OS.get_cmdline_args():
221
+ print(argument)
222
+ if argument.find("=") > -1:
223
+ var key_value = argument.split("=")
224
+ arguments[key_value[0].lstrip("--")] = key_value[1]
225
+ else:
226
+ # Options without an argument will be present in the dictionary,
227
+ # with the value set to an empty string.
228
+ arguments[argument.lstrip("--")] = ""
229
+
230
+ return arguments
231
+
232
+ func _get_speedup():
233
+ print(args)
234
+ return args.get("speedup", str(speed_up)).to_int()
235
+
236
+ func _get_port():
237
+ return args.get("port", DEFAULT_PORT).to_int()
238
+
239
+ func _set_seed():
240
+ var _seed = args.get("env_seed", DEFAULT_SEED).to_int()
241
+ seed(_seed)
242
+
243
+ func _set_action_repeat():
244
+ action_repeat = args.get("action_repeat", str(action_repeat)).to_int()
245
+
246
+ func disconnect_from_server():
247
+ stream.disconnect_from_host()
248
+
249
+
250
+
251
+ func handle_message() -> bool:
252
+ # get json message: reset, step, close
253
+ var message = _get_dict_json_message()
254
+ if message["type"] == "close":
255
+ print("received close message, closing game")
256
+ get_tree().quit()
257
+ get_tree().set_pause(false)
258
+ return true
259
+
260
+ if message["type"] == "reset":
261
+ print("resetting all agents")
262
+ _reset_all_agents()
263
+ just_reset = true
264
+ get_tree().set_pause(false)
265
+ #print("resetting forcing draw")
266
+ # RenderingServer.force_draw()
267
+ # var obs = _get_obs_from_agents()
268
+ # print("obs ", obs)
269
+ # var reply = {
270
+ # "type": "reset",
271
+ # "obs": obs
272
+ # }
273
+ # _send_dict_as_json_message(reply)
274
+ return true
275
+
276
+ if message["type"] == "call":
277
+ var method = message["method"]
278
+ var returns = _call_method_on_agents(method)
279
+ var reply = {
280
+ "type": "call",
281
+ "returns": returns
282
+ }
283
+ print("calling method from Python")
284
+ _send_dict_as_json_message(reply)
285
+ return handle_message()
286
+
287
+ if message["type"] == "action":
288
+ var action = message["action"]
289
+ _set_agent_actions(action)
290
+ need_to_send_obs = true
291
+ get_tree().set_pause(false)
292
+ return true
293
+
294
+ print("message was not handled")
295
+ return false
296
+
297
+ func _call_method_on_agents(method):
298
+ var returns = []
299
+ for agent in agents:
300
+ returns.append(agent.call(method))
301
+
302
+ return returns
303
+
304
+
305
+ func _reset_agents_if_done():
306
+ for agent in agents:
307
+ if agent.get_done():
308
+ agent.set_done_false()
309
+
310
+ func _reset_all_agents():
311
+ for agent in agents:
312
+ agent.needs_reset = true
313
+ #agent.reset()
314
+
315
+ func _get_obs_from_agents():
316
+ var obs = []
317
+ for agent in agents:
318
+ obs.append(agent.get_obs())
319
+
320
+ return obs
321
+
322
+ func _get_reward_from_agents():
323
+ var rewards = []
324
+ for agent in agents:
325
+ rewards.append(agent.get_reward())
326
+ agent.zero_reward()
327
+ return rewards
328
+
329
+ func _get_done_from_agents():
330
+ var dones = []
331
+ for agent in agents:
332
+ var done = agent.get_done()
333
+ if done: agent.set_done_false()
334
+ dones.append(done)
335
+ return dones
336
+
337
+ func _set_agent_actions(actions):
338
+ for i in range(len(actions)):
339
+ agents[i].set_action(actions[i])
340
+
341
+ func clamp_array(arr : Array, min:float, max:float):
342
+ var output : Array = []
343
+ for a in arr:
344
+ output.append(clamp(a, min, max))
345
+ return output
asset-license.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ 3DLander Environment made by Ivan-267 using Godot, Godot RL Agents, and Blender.
2
+
3
+ The following license is only for the assets (.blend files) in the folder "blender":
4
+ Author: https://github.com/Ivan-267
5
+ License: https://creativecommons.org/licenses/by/4.0/
blender/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ## Needs the import files to work correctly
2
+ !*.import
blender/lander.blend ADDED
Binary file (968 kB). View file
 
blender/lander.blend.import ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [remap]
2
+
3
+ importer="scene"
4
+ importer_version=1
5
+ type="PackedScene"
6
+ uid="uid://c5sv7fju6uiew"
7
+ path="res://.godot/imported/lander.blend-f9a5f8cc1cc4747a914fa5968f7bc25e.scn"
8
+
9
+ [deps]
10
+
11
+ source_file="res://blender/lander.blend"
12
+ dest_files=["res://.godot/imported/lander.blend-f9a5f8cc1cc4747a914fa5968f7bc25e.scn"]
13
+
14
+ [params]
15
+
16
+ nodes/root_type="RigidBody3D"
17
+ nodes/root_name="Lander"
18
+ nodes/apply_root_scale=true
19
+ nodes/root_scale=1.0
20
+ meshes/ensure_tangents=true
21
+ meshes/generate_lods=true
22
+ meshes/create_shadow_meshes=true
23
+ meshes/light_baking=1
24
+ meshes/lightmap_texel_size=0.2
25
+ meshes/force_disable_compression=false
26
+ skins/use_named_skins=true
27
+ animation/import=true
28
+ animation/fps=30
29
+ animation/trimming=false
30
+ animation/remove_immutable_tracks=true
31
+ import_script/path=""
32
+ _subresources={}
33
+ gltf/naming_version=0
34
+ gltf/embedded_image_handling=1
35
+ blender/nodes/visible=0
36
+ blender/nodes/punctual_lights=true
37
+ blender/nodes/cameras=true
38
+ blender/nodes/custom_properties=true
39
+ blender/nodes/modifiers=1
40
+ blender/meshes/colors=false
41
+ blender/meshes/uvs=true
42
+ blender/meshes/normals=true
43
+ blender/meshes/tangents=true
44
+ blender/meshes/skins=2
45
+ blender/meshes/export_bones_deforming_mesh_only=false
46
+ blender/materials/unpack_enabled=true
47
+ blender/materials/export_materials=1
48
+ blender/animation/limit_playback=true
49
+ blender/animation/always_sample=true
50
+ blender/animation/group_tracks=true
blender/landing-leg.blend ADDED
Binary file (899 kB). View file
 
blender/landing-leg.blend.import ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [remap]
2
+
3
+ importer="scene"
4
+ importer_version=1
5
+ type="PackedScene"
6
+ uid="uid://drqbjpjw2hiic"
7
+ path="res://.godot/imported/landing-leg.blend-49137b7f84c9ab66b10d0c88cd578255.scn"
8
+
9
+ [deps]
10
+
11
+ source_file="res://blender/landing-leg.blend"
12
+ dest_files=["res://.godot/imported/landing-leg.blend-49137b7f84c9ab66b10d0c88cd578255.scn"]
13
+
14
+ [params]
15
+
16
+ nodes/root_type="RigidBody3D"
17
+ nodes/root_name="LandingLeg"
18
+ nodes/apply_root_scale=true
19
+ nodes/root_scale=1.0
20
+ meshes/ensure_tangents=true
21
+ meshes/generate_lods=true
22
+ meshes/create_shadow_meshes=true
23
+ meshes/light_baking=1
24
+ meshes/lightmap_texel_size=0.2
25
+ meshes/force_disable_compression=false
26
+ skins/use_named_skins=true
27
+ animation/import=true
28
+ animation/fps=30
29
+ animation/trimming=false
30
+ animation/remove_immutable_tracks=true
31
+ import_script/path=""
32
+ _subresources={}
33
+ gltf/naming_version=0
34
+ gltf/embedded_image_handling=1
35
+ blender/nodes/visible=0
36
+ blender/nodes/punctual_lights=true
37
+ blender/nodes/cameras=true
38
+ blender/nodes/custom_properties=true
39
+ blender/nodes/modifiers=1
40
+ blender/meshes/colors=false
41
+ blender/meshes/uvs=true
42
+ blender/meshes/normals=true
43
+ blender/meshes/tangents=true
44
+ blender/meshes/skins=2
45
+ blender/meshes/export_bones_deforming_mesh_only=false
46
+ blender/materials/unpack_enabled=true
47
+ blender/materials/export_materials=1
48
+ blender/animation/limit_playback=true
49
+ blender/animation/always_sample=true
50
+ blender/animation/group_tracks=true
icon.svg ADDED
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29ea0e922e2690d3073b12386179e24a248a5a28193d41d03cdbe8b42400b875
3
+ size 67297
project.godot ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ; Engine configuration file.
2
+ ; It's best edited using the editor UI and not directly,
3
+ ; since the parameters that go here are not all obvious.
4
+ ;
5
+ ; Format:
6
+ ; [section] ; section goes between []
7
+ ; param=value ; assign values to parameters
8
+
9
+ config_version=5
10
+
11
+ [application]
12
+
13
+ config/name="Lander3D"
14
+ run/main_scene="res://scenes/training_scene/training_scene.tscn"
15
+ config/features=PackedStringArray("4.2", "C#", "Forward Plus")
16
+ config/icon="res://icon.svg"
17
+
18
+ [audio]
19
+
20
+ buses/default_bus_layout=""
21
+
22
+ [dotnet]
23
+
24
+ project/assembly_name="Spaceship"
25
+
26
+ [editor_plugins]
27
+
28
+ enabled=PackedStringArray("res://addons/godot_rl_agents/plugin.cfg")
29
+
30
+ [input]
31
+
32
+ up_thruster={
33
+ "deadzone": 0.5,
34
+ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
35
+ ]
36
+ }
37
+ forward_thruster={
38
+ "deadzone": 0.5,
39
+ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
40
+ ]
41
+ }
42
+ back_thruster={
43
+ "deadzone": 0.5,
44
+ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
45
+ ]
46
+ }
47
+ left_thruster={
48
+ "deadzone": 0.5,
49
+ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
50
+ ]
51
+ }
52
+ right_thruster={
53
+ "deadzone": 0.5,
54
+ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
55
+ ]
56
+ }
57
+ turn_left_thruster={
58
+ "deadzone": 0.5,
59
+ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"echo":false,"script":null)
60
+ ]
61
+ }
62
+ turn_right_thruster={
63
+ "deadzone": 0.5,
64
+ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
65
+ ]
66
+ }
readme.md ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## 3D Lander Environment
2
+
3
+ ![lander_scr_1](https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/66bca4d4-17cb-4618-b4be-ac5a04144927)
4
+
5
+ This environment was inspired by the gymnasium Lunar Lander env.
6
+
7
+ The goal is to land safely as close to the goal as possible.
8
+ It is not required to land inside the goal zone, but landing closer to the center of the zone gives a higher reward.
9
+
10
+ On each (re)start, the lander is randomly positioned with a random velocity added.
11
+
12
+ ### Observations:
13
+ Vector based, including:
14
+
15
+ - Linear and angular velocity of the lander in the lander's frame of reference,
16
+ - Current step / episode length in steps,
17
+ - How many of the lander's legs are currently in contact with the ground,
18
+ - The orientation of the lander (basis y and x vectors),
19
+ - The position of the goal (landing zone) relative to the lander,
20
+ - The direction difference between the goal direction (Y axis pointing upward) and the current direction,
21
+ - Observations from a RayCast sensor attached to the lander.
22
+
23
+ ### Action space:
24
+ For each thruster that the RL agent can control, a discrete action is used of size 2 (with possible values being 0 - thruster off, or 1 - thruster on).
25
+ The entire action space is defined as:
26
+
27
+ ```gdscript
28
+ func get_action_space() -> Dictionary:
29
+ return {
30
+ "back_thruster" : {
31
+ "size": 2,
32
+ "action_type": "discrete"
33
+ },
34
+ "forward_thruster" : {
35
+ "size": 2,
36
+ "action_type": "discrete"
37
+ },
38
+ "left_thruster" : {
39
+ "size": 2,
40
+ "action_type": "discrete"
41
+ },
42
+ "right_thruster" : {
43
+ "size": 2,
44
+ "action_type": "discrete"
45
+ },
46
+ "turn_left_thruster" : {
47
+ "size": 2,
48
+ "action_type": "discrete"
49
+ },
50
+ "turn_right_thruster" : {
51
+ "size": 2,
52
+ "action_type": "discrete"
53
+ },
54
+ "up_thruster" : {
55
+ "size": 2,
56
+ "action_type": "discrete"
57
+ },
58
+ }
59
+ ```
60
+
61
+ ### Rewards and episode end conditions:
62
+ The requirement for "successfully landing" includes all legs being on the ground, velocities being low and thruster activity being very low (the thresholds can be adjusted in the `_is_goal_reached()` method of `Lander.gd`).
63
+
64
+ Every time a leg collides the ground, a positive reward is given. Every time a leg loses contact with the ground, a negative reward is given (in the current version, there may be a case where the negative reward is given after restarting the episode, this hasn't been checked in-depth).
65
+
66
+ The episode is restarted if:
67
+ - The lander successfully lands (along with a positive reward reduced by the distance from the center of the landing area).
68
+ - The body of lander collides with the ground or one of the walls around the game area (along with a negative reward)
69
+ - The episodes times out (along with a negative reward)
70
+
71
+ On every physics step, a reward is added based on:
72
+ - Distance to goal delta (reward is positive or negative depending on whether the distance is decreasing or increasing)
73
+ - Linear velocity delta (positive if the velocity is decreasing, negative if increasing)
74
+ - Angular velocity delta (same as above)
75
+ - Direction to goal difference delta (positive if the difference from the goal direction is decreasing, negative if increasing)
76
+ - Thruster usage delta (positive if less thrusters are used than before, negative if more thrusters are used than before)
77
+
78
+ ### Lander:
79
+ ![lander](https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/290d73b1-789d-4af0-8911-3be584b9c0a8)
80
+
81
+ The lander consists of a RigidBody for the main body and a RigidBody for each leg.
82
+ The legs are connected by a `Generic6DOFJoint3D` to the body.
83
+
84
+ A 360 degree RayCast sensor is added to the lander to enable it to detect the terrain features as well as the invisible walls / game area boundaries.
85
+
86
+ The motion of the lander is caused by applying forces from the locations of the thrusters.
87
+
88
+ ### Terrain generation:
89
+ `Terrain` class attached to the Terrain node in GameScene generates the terrain for the environment:
90
+
91
+ ![lander_terrain](https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/ff3aa7d7-259a-436e-85b4-039b66f0ff01)
92
+
93
+ The `training mode`, enabled by default but disabled for the testing scenes, makes the generation slightly faster for training, as it does not calculate the normals or ambient occlusion texture.
94
+ In addition, it makes the terrain regenerate only some of the times on episode restart, rather than every time which is used during inference.
95
+
96
+ ![terrain_parameters_noise](https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/0e3f5176-2c7f-48c6-ad46-b98e880b7b26)
97
+
98
+ Altering the main noise texture, along with changing `size`, `subdivisions` and the `height multiplier`,
99
+ affects the main shape of the terrain.
100
+
101
+ A part of the terrain is made relatively flat so that there is always somewhere the lander can land safely.
102
+ You can adjust the radius of that area by changing `Landing Surface Radius`.
103
+
104
+ ![surface_radius_changes](https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/29361c4b-2b9d-42e5-bcdc-5b7fa7131775)
105
+ (Left: Landing Surface Radius = 10, Right: Landing Surface Radius = 60)
106
+
107
+ The position of the landing surface is randomized when the terrain is generated.
108
+ You can adjust how far away from the center it can be by using the `Landing Surface Max Dist From Center Ratio` parameter.
109
+
110
+ `Regenerate Terrain` can be used to regenerate the terrain in the inspector after changing settings. This is not done automatically after every change as regenerating the terrain could take some time, especially if a lot of subdivisions are used.
111
+
112
+ ## Training:
113
+ The included onnx file was trained with SB3.
114
+
115
+ Because this is the first environment to use only discrete actions which are not fully supported with Godot-RL with SB3 at this moment, this environment was trained using relevant files [from the discrete actions branch](https://github.com/edbeeching/godot_rl_agents/tree/discrete_actions_experimental) of Godot-RL.
116
+
117
+ You may be able to train the environment with the main branch and run inference from Python, but exporting to onnx will need require this branch and is recommended for training as well.
118
+
119
+ The parameters used during training were (you can set them by modifying [sb3_example](https://github.com/edbeeching/godot_rl_agents/blob/main/examples/stable_baselines3_example.py)):
120
+ ```
121
+ model = PPO("MultiInputPolicy", env, ent_coef=0.02, n_steps=768, verbose=2, tensorboard_log=args.experiment_dir,
122
+ learning_rate=learning_rate, n_epochs=4)
123
+ ```
124
+
125
+ And also, `n_parallel=4` argument was used when for training.
126
+
127
+ Training stats screenshot from Tensorboard:
128
+ ![lander3d_training_stats](https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/6e6e432f-6e99-4451-93d2-66c9936ebf8d)
129
+
130
+ ## Running inference:
131
+ To start inference using the pretrained onnx, open the `testing_scene` in Godot Editor, then press `F6` or click on the scene starting icon:
132
+
133
+ ![lander3d_testing_scene](https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/4d54189d-4749-46af-8ba7-2edc955f7b3a)
134
+
135
+ You can adjust the `Speed Up` parameter of the `Sync` node to change the speed of the environment.
136
+
137
+ Due to using discrete actions, this environment comes packaged with the plugin from the [discrete actions PR](https://github.com/edbeeching/godot_rl_agents_plugin/pull/16), which adds the support.
138
+
139
+ ## Manually playing:
140
+ You can start the `Manual Test Scene` to control the environment manually.
141
+
142
+ https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/03b3b316-e2e0-4340-b739-73487484f02a
143
+
144
+ `WASD` activate the 4-direction `navigation` thrusters,
145
+ `Q` and `E` activate the `rotation` thrusters,
146
+ `SPACE` activates the main `up` thruster.
147
+
148
+ The camera is not optimally adjusted for human control, as the scene is mainly there to test out the behavior of the environment.
149
+
150
+ ## Known issues:
151
+ There is a rare error caused by an `inf` value being sent by an observation noticed during training.
scenes/game_scene/CameraFollowLander.gd ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Camera3D
2
+
3
+ ## Camera extended to follow the lander.
4
+
5
+ @onready var _lander = $"../Lander"._lander
6
+
7
+ func _ready():
8
+ global_transform = Transform3D.IDENTITY.rotated_local(Vector3.LEFT, 0.25)
9
+
10
+ # Called every frame. 'delta' is the elapsed time since the previous frame.
11
+ func _physics_process(delta):
12
+ var temporary_transform = Transform3D(global_transform)
13
+
14
+ temporary_transform.origin = (
15
+ _lander.global_position + global_transform.basis.y + global_transform.basis.z * 7.0
16
+ )
17
+
18
+ global_transform = global_transform.interpolate_with(temporary_transform, 10.0 * delta)
19
+ pass
scenes/game_scene/Lander.gd ADDED
@@ -0,0 +1,329 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends Node3D
2
+ class_name Lander
3
+
4
+ ## Main class for the Lander, also handles setting rewards and restarting the episode.
5
+ @export var show_successful_landing_debug_text := false
6
+
7
+ @export var min_initial_velocity: float = 5.0
8
+ @export var max_initial_velocity: float = 10.0
9
+ @export var max_random_position_distance_from_center: float = 50.0
10
+
11
+ @export var up_thruster_max_force: float = 500.0
12
+ @export var navigation_thruster_max_force: float = 250.0
13
+
14
+ @onready var ai_controller: LanderAIController = $AIController3D
15
+
16
+ # In case of error: "Trying to assign value of type 'Node3D'...",
17
+ # try to double click on blender\lander.blend in Godot and click reimport.
18
+ # (if needed, repeat for landing-leg.blend too)
19
+ @onready var _lander: RigidBody3D = $Lander
20
+ var _landing_legs: Array[RigidBody3D]
21
+ var _landing_leg_initial_transforms: Dictionary
22
+
23
+ @export var terrain: Terrain
24
+ @export var raycast_sensor: RayCastSensor3D
25
+
26
+ @export var up_thruster: Thruster
27
+ @export var left_thruster: Thruster
28
+ @export var right_thruster: Thruster
29
+ @export var forward_thruster: Thruster
30
+ @export var back_thruster: Thruster
31
+ @export var turn_left_thruster: Thruster
32
+ @export var turn_right_thruster: Thruster
33
+
34
+ var thrusters: Array
35
+
36
+ var landing_position := Vector3(0.0, 0.0, 0.0)
37
+ var episode_ended_unsuccessfully_reward := -5.0
38
+
39
+ var times_restarted := 0
40
+ var _initial_transform: Transform3D
41
+
42
+ var _legs_in_contact_with_ground: int
43
+
44
+ var _previous_goal_distance: float
45
+ var _previous_angular_velocity: float
46
+ var _previous_direction_difference: float
47
+ var _previous_linear_velocity: float
48
+
49
+ var _thruster_reward_multiplier: float = 0.0325
50
+ var _shaped_reward_multiplier: float = 0.3
51
+
52
+ var _previous_thruster_usage: float
53
+
54
+ func _ready():
55
+ ai_controller.init(self)
56
+
57
+ _landing_legs.append_array([
58
+ $LandingLeg,
59
+ $LandingLeg2,
60
+ $LandingLeg3,
61
+ $LandingLeg4
62
+ ])
63
+
64
+ for landing_leg in _landing_legs:
65
+ _landing_leg_initial_transforms[landing_leg] = landing_leg.global_transform
66
+
67
+ _initial_transform = _lander.global_transform
68
+
69
+ thrusters.append_array([
70
+ up_thruster,
71
+ left_thruster,
72
+ right_thruster,
73
+ forward_thruster,
74
+ back_thruster,
75
+ turn_left_thruster,
76
+ turn_right_thruster
77
+ ])
78
+
79
+ reset()
80
+
81
+ func reset():
82
+ terrain.maybe_generate_terrain()
83
+ times_restarted += 1
84
+
85
+ var random_velocity = Vector3(
86
+ randf_range(-1.0, 1.0),
87
+ randf_range(-1.0, 1.0),
88
+ randf_range(-1.0, 1.0)
89
+ ).normalized() * randf_range(min_initial_velocity, max_initial_velocity)
90
+
91
+ var random_position_offset = Vector3(
92
+ randf_range(-1.0, 1.0),
93
+ 0,
94
+ randf_range(-1.0, 1.0)
95
+ ).normalized() * randf_range(0.0, max_random_position_distance_from_center)
96
+
97
+ _lander.global_transform = _initial_transform
98
+ _lander.global_transform.origin += random_position_offset
99
+ _lander.linear_velocity = random_velocity
100
+ _lander.angular_velocity = Vector3.ZERO
101
+
102
+ for landing_leg in _landing_legs:
103
+ landing_leg.global_transform = _landing_leg_initial_transforms[landing_leg]
104
+ landing_leg.global_transform.origin += random_position_offset
105
+ landing_leg.linear_velocity = random_velocity
106
+ landing_leg.angular_velocity = Vector3.ZERO
107
+
108
+ for thruster in thrusters:
109
+ thruster.thruster_strength = 0.0
110
+
111
+ landing_position = terrain.landing_position
112
+
113
+ _previous_linear_velocity = get_normalized_linear_velocity()
114
+ _previous_goal_distance = _get_normalized_distance_to_goal()
115
+ _previous_angular_velocity = get_normalized_angular_velocity()
116
+ _previous_direction_difference = get_player_goal_direction_difference()
117
+
118
+ _previous_thruster_usage = _get_normalized_current_total_thruster_strength()
119
+ pass
120
+
121
+ func _physics_process(delta):
122
+ _end_episode_on_goal_reached()
123
+ _update_reward()
124
+
125
+ if (ai_controller.heuristic == "human"):
126
+ up_thruster.thruster_strength = (
127
+ int(Input.is_action_pressed("up_thruster"))
128
+ ) * up_thruster_max_force
129
+
130
+ left_thruster.thruster_strength = (
131
+ int(Input.is_action_pressed("left_thruster"))
132
+ ) * navigation_thruster_max_force
133
+
134
+ right_thruster.thruster_strength = (
135
+ int(Input.is_action_pressed("right_thruster"))
136
+ ) * navigation_thruster_max_force
137
+
138
+ forward_thruster.thruster_strength = (
139
+ int(Input.is_action_pressed("forward_thruster"))
140
+ ) * navigation_thruster_max_force
141
+
142
+ back_thruster.thruster_strength = (
143
+ int(Input.is_action_pressed("back_thruster"))
144
+ ) * navigation_thruster_max_force
145
+
146
+ turn_left_thruster.thruster_strength = (
147
+ int(Input.is_action_pressed("turn_left_thruster"))
148
+ ) * navigation_thruster_max_force
149
+
150
+ turn_right_thruster.thruster_strength = (
151
+ int(Input.is_action_pressed("turn_right_thruster"))
152
+ ) * navigation_thruster_max_force
153
+
154
+ for thruster in thrusters:
155
+ _lander.apply_force(
156
+ thruster.global_transform.basis.y * thruster.thruster_strength,
157
+ thruster.global_position - _lander.global_position
158
+ )
159
+
160
+ _reset_if_needed()
161
+ pass
162
+
163
+ func _end_episode_on_goal_reached():
164
+ if _is_goal_reached():
165
+ if show_successful_landing_debug_text:
166
+ print("Successfully landed")
167
+
168
+ # The reward for succesfully landing is reduced by
169
+ # the distance from the goal position
170
+ var successfully_landed_reward: float = (
171
+ 10.0
172
+ - _get_normalized_distance_to_goal() * 6.0
173
+ )
174
+ _end_episode(successfully_landed_reward)
175
+
176
+ func _end_episode(final_reward: float = 0.0):
177
+ ai_controller.reward += final_reward
178
+ ai_controller.needs_reset = true
179
+ ai_controller.done = true
180
+
181
+ func _reset_if_needed():
182
+ if ai_controller.needs_reset:
183
+ reset()
184
+ ai_controller.reset()
185
+
186
+ func _update_reward():
187
+ if times_restarted == 0:
188
+ return
189
+
190
+ # Positive reward if the parameters are approaching the goal values,
191
+ # negative reward if they are moving away from the goal values
192
+ var vel_reward := (_previous_linear_velocity - get_normalized_linear_velocity())
193
+ var thruster_usage_reward := (_previous_thruster_usage - _get_normalized_current_total_thruster_strength()) * 0.06
194
+ var ang_vel_reward := (_previous_angular_velocity - get_normalized_angular_velocity())
195
+
196
+ var dist_reward := 0.0
197
+ var dir_reward := 0.0
198
+
199
+ if _legs_in_contact_with_ground == 0:
200
+ dist_reward = (_previous_goal_distance - _get_normalized_distance_to_goal()) * 6.0
201
+ dir_reward = (_previous_direction_difference - get_player_goal_direction_difference()) * 0.25
202
+
203
+ ai_controller.reward += (
204
+ dist_reward +
205
+ vel_reward +
206
+ dir_reward +
207
+ ang_vel_reward +
208
+ thruster_usage_reward
209
+ ) * 65.0 * _shaped_reward_multiplier
210
+
211
+ _previous_linear_velocity = get_normalized_linear_velocity()
212
+ _previous_goal_distance = _get_normalized_distance_to_goal()
213
+ _previous_angular_velocity = get_normalized_angular_velocity()
214
+ _previous_direction_difference = get_player_goal_direction_difference()
215
+
216
+ _previous_thruster_usage = _get_normalized_current_total_thruster_strength()
217
+ pass
218
+
219
+ # Returns the difference between current direction and goal direction in range 0,1
220
+ # If 1, the angle is 180 degrees, if 0, the direction is perfectly aligned.
221
+ func get_player_goal_direction_difference() -> float:
222
+ return (1.0 + _lander.global_transform.basis.y.dot(-Vector3.UP)) / 2.0
223
+
224
+ func _is_goal_reached() -> bool:
225
+ return (
226
+ not ai_controller.done and
227
+ _legs_in_contact_with_ground == 4 and
228
+ _lander.linear_velocity.length() < 0.015 and
229
+ _lander.angular_velocity.length() < 0.5 and
230
+ _get_normalized_current_total_thruster_strength() < 0.01
231
+ )
232
+
233
+ func _get_current_distance_to_goal() -> float:
234
+ return _lander.global_position.distance_to(landing_position)
235
+
236
+ func _get_normalized_distance_to_goal() -> float:
237
+ var playing_area_size = get_playing_area_size()
238
+ return (
239
+ _lander.global_position.distance_to(landing_position) /
240
+ Vector3(
241
+ playing_area_size.x / 2,
242
+ playing_area_size.y,
243
+ playing_area_size.x / 2,
244
+ ).length()
245
+ )
246
+
247
+ func get_goal_position_in_player_reference() -> Vector3:
248
+
249
+ var local_position: Vector3 = _lander.to_local(landing_position)
250
+ var playing_area_size: Vector3 = get_playing_area_size()
251
+
252
+ var local_size: Vector3 = (
253
+ _lander.global_transform.basis.inverse() *
254
+ Vector3(
255
+ playing_area_size.x / 2.0,
256
+ playing_area_size.y,
257
+ playing_area_size.z / 2.0,
258
+ )
259
+ )
260
+ return local_position / local_size
261
+
262
+ ## Returns the normalized position of the center of the terrain in player's reference
263
+ func get_terrain_center_position_in_player_reference() -> Vector3:
264
+ var local_position = _lander.to_local(terrain.global_position)
265
+ var playing_area_size = get_playing_area_size()
266
+ var local_size = (
267
+ _lander.global_transform.basis.inverse() *
268
+ Vector3(
269
+ playing_area_size.x / 2,
270
+ playing_area_size.y,
271
+ playing_area_size.x / 2,
272
+ )
273
+ )
274
+ return local_position / local_size
275
+
276
+ func get_velocity_in_player_reference() -> Vector3:
277
+ return (
278
+ _lander.global_transform.basis.inverse() *
279
+ _lander.linear_velocity
280
+ )
281
+
282
+ func _get_normalized_current_total_thruster_strength() -> float:
283
+ var thruster_strength_total: float = 0.0
284
+ for thruster in thrusters:
285
+ thruster_strength_total += thruster.thruster_strength / up_thruster_max_force
286
+ return thruster_strength_total
287
+
288
+ func get_angular_velocity_in_player_reference() -> Vector3:
289
+ return _lander.global_transform.basis.inverse() * _lander.angular_velocity
290
+
291
+ func get_playing_area_size() -> Vector3:
292
+ return Vector3(
293
+ terrain.size.x,
294
+ 250.0,
295
+ terrain.size.y
296
+ )
297
+
298
+ func get_orientation_as_array() -> Array[float]:
299
+ var basis_y: Vector3 = _lander.global_transform.basis.y
300
+ var basis_x: Vector3 = _lander.global_transform.basis.x
301
+ return [
302
+ basis_y.x,
303
+ basis_y.y,
304
+ basis_y.z,
305
+ basis_x.x,
306
+ basis_x.y,
307
+ basis_x.z
308
+ ]
309
+
310
+ func get_normalized_linear_velocity() -> float:
311
+ return minf(50.0, _lander.linear_velocity.length()) / 50.0
312
+
313
+ func get_normalized_angular_velocity() -> float:
314
+ return minf(10.0, _lander.angular_velocity.length()) / 10.0
315
+
316
+ func _on_lander_body_entered(body):
317
+ _end_episode(episode_ended_unsuccessfully_reward)
318
+
319
+ func get_lander_global_position():
320
+ return _lander.global_position
321
+
322
+ func _on_landing_leg_body_exited(body):
323
+ # Possible bug to consider: upon restarting, this reward may be given in the first frame of the next episode
324
+ _legs_in_contact_with_ground -= 1
325
+ ai_controller.reward -= 0.25
326
+
327
+ func _on_landing_leg_body_entered(body):
328
+ _legs_in_contact_with_ground += 1
329
+ ai_controller.reward += 0.25
scenes/game_scene/Lander.tscn ADDED
@@ -0,0 +1,871 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=37 format=3 uid="uid://dxflbek2f52ks"]
2
+
3
+ [ext_resource type="Script" path="res://scenes/game_scene/Lander.gd" id="1_2yq6u"]
4
+ [ext_resource type="PackedScene" uid="uid://c5sv7fju6uiew" path="res://blender/lander.blend" id="2_s4oxe"]
5
+ [ext_resource type="Script" path="res://scenes/game_scene/Thruster.gd" id="3_ylucp"]
6
+ [ext_resource type="PackedScene" uid="uid://drqbjpjw2hiic" path="res://blender/landing-leg.blend" id="4_gp4fc"]
7
+ [ext_resource type="Script" path="res://scenes/game_scene/LanderAIController3D.gd" id="5_w0bd1"]
8
+ [ext_resource type="Script" path="res://addons/godot_rl_agents/sensors/sensors_3d/RaycastSensor3D.gd" id="6_03nxx"]
9
+
10
+ [sub_resource type="Gradient" id="Gradient_nkj1p"]
11
+ offsets = PackedFloat32Array(0, 0.568075)
12
+ colors = PackedColorArray(0.64, 0.64, 0.64, 0.831373, 0.42, 0.42, 0.42, 0)
13
+
14
+ [sub_resource type="GradientTexture1D" id="GradientTexture1D_0sn4e"]
15
+ gradient = SubResource("Gradient_nkj1p")
16
+ width = 128
17
+
18
+ [sub_resource type="Curve" id="Curve_id7xf"]
19
+ _data = [Vector2(0.00218819, 0.210526), 0.0, 0.0, 0, 0, Vector2(1, 0.757895), 0.0, 0.0, 0, 0]
20
+ point_count = 2
21
+
22
+ [sub_resource type="CurveTexture" id="CurveTexture_867j3"]
23
+ curve = SubResource("Curve_id7xf")
24
+
25
+ [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_rsa34"]
26
+ direction = Vector3(0, -1, 0)
27
+ spread = 0.0
28
+ initial_velocity_min = 1.0
29
+ initial_velocity_max = 1.0
30
+ gravity = Vector3(0, 0, 0)
31
+ scale_max = 2.0
32
+ scale_curve = SubResource("CurveTexture_867j3")
33
+ color_ramp = SubResource("GradientTexture1D_0sn4e")
34
+
35
+ [sub_resource type="Gradient" id="Gradient_0sav6"]
36
+ offsets = PackedFloat32Array(0, 0.643541)
37
+ colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)
38
+
39
+ [sub_resource type="GradientTexture2D" id="GradientTexture2D_vxa0k"]
40
+ gradient = SubResource("Gradient_0sav6")
41
+ use_hdr = true
42
+ fill = 1
43
+ fill_from = Vector2(0.5, 0.5)
44
+
45
+ [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vp3n7"]
46
+ transparency = 1
47
+ shading_mode = 0
48
+ vertex_color_use_as_albedo = true
49
+ albedo_color = Color(1, 1, 1, 0.529412)
50
+ albedo_texture = SubResource("GradientTexture2D_vxa0k")
51
+ billboard_mode = 3
52
+ billboard_keep_scale = true
53
+ particles_anim_h_frames = 1
54
+ particles_anim_v_frames = 1
55
+ particles_anim_loop = false
56
+
57
+ [sub_resource type="QuadMesh" id="QuadMesh_u5of1"]
58
+ material = SubResource("StandardMaterial3D_vp3n7")
59
+ size = Vector2(0.6, 0.6)
60
+
61
+ [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_ot7am"]
62
+ direction = Vector3(0, -1, 0)
63
+ spread = 0.0
64
+ initial_velocity_min = 1.0
65
+ initial_velocity_max = 1.0
66
+ gravity = Vector3(0, 0, 0)
67
+ scale_max = 1.5
68
+ scale_curve = SubResource("CurveTexture_867j3")
69
+ color_ramp = SubResource("GradientTexture1D_0sn4e")
70
+
71
+ [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_3l3es"]
72
+ direction = Vector3(0, -1, 0)
73
+ spread = 0.0
74
+ initial_velocity_min = 1.0
75
+ initial_velocity_max = 1.0
76
+ gravity = Vector3(0, 0, 0)
77
+ scale_curve = SubResource("CurveTexture_867j3")
78
+ color_ramp = SubResource("GradientTexture1D_0sn4e")
79
+
80
+ [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_k81u0"]
81
+ direction = Vector3(0, -1, 0)
82
+ spread = 0.0
83
+ initial_velocity_min = 1.0
84
+ initial_velocity_max = 1.0
85
+ gravity = Vector3(0, 0, 0)
86
+ scale_curve = SubResource("CurveTexture_867j3")
87
+ color_ramp = SubResource("GradientTexture1D_0sn4e")
88
+
89
+ [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_5yx2o"]
90
+ direction = Vector3(0, -1, 0)
91
+ spread = 0.0
92
+ initial_velocity_min = 1.0
93
+ initial_velocity_max = 1.0
94
+ gravity = Vector3(0, 0, 0)
95
+ scale_curve = SubResource("CurveTexture_867j3")
96
+ color_ramp = SubResource("GradientTexture1D_0sn4e")
97
+
98
+ [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_pnaje"]
99
+ direction = Vector3(0, -1, 0)
100
+ spread = 0.0
101
+ initial_velocity_min = 1.0
102
+ initial_velocity_max = 1.0
103
+ gravity = Vector3(0, 0, 0)
104
+ scale_curve = SubResource("CurveTexture_867j3")
105
+ color_ramp = SubResource("GradientTexture1D_0sn4e")
106
+
107
+ [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_krfta"]
108
+ direction = Vector3(0, -1, 0)
109
+ spread = 0.0
110
+ initial_velocity_min = 1.0
111
+ initial_velocity_max = 1.0
112
+ gravity = Vector3(0, 0, 0)
113
+ scale_curve = SubResource("CurveTexture_867j3")
114
+ color_ramp = SubResource("GradientTexture1D_0sn4e")
115
+
116
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_tvjil"]
117
+ points = PackedVector3Array(0.892248, 1, 0.692248, 1.2, 0.692248, 0.692248, 0.892248, 1, -0.692443, -0.892483, 1, 0.692248, 0.892248, 0.692248, 1, 1.2, 0.692248, -0.692443, 1.2, -0.692443, 0.692248, 0.892248, 0.692248, -1, -0.892483, 1, -0.692443, -1.2, 0.692248, 0.692248, -0.892483, 0.692248, 1, 0.892248, -0.692443, 1, 1.2, -0.692443, -0.692443, 0.892248, -1, 0.692248, 0.892248, -0.692443, -1, -0.892483, 0.692248, -1, -1.2, 0.692248, -0.692443, -1.2, -0.692443, 0.692248, -0.892483, -0.692443, 1, 0.892248, -1, -0.692443, -0.892483, -1, 0.692248, -0.892483, -0.692443, -1, -1.2, -0.692443, -0.692443, -0.892483, -1, -0.692443)
118
+
119
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_oxrum"]
120
+ points = PackedVector3Array(-7.45058e-09, -1.14764, 0.0999804, 0.0866025, -1.14764, 0.0499804, -7.45058e-09, -0.947639, 0.0499804, -0.0866025, -1.14764, 0.0499804, 0.0866025, -1.14764, -0.0500196, 0.0433013, -0.947639, 0.0249804, -0.0433013, -0.947639, 0.0249804, -0.0866025, -1.14764, -0.0500196, -7.45058e-09, -1.14764, -0.1, -7.45058e-09, -0.947639, -0.0500196, 0.0433013, -0.947639, -0.0250196, -0.0433013, -0.947639, -0.0250196)
121
+
122
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_hn0x3"]
123
+ points = PackedVector3Array(-0.2, 0.961511, -0.138489, -0.2, 0.961511, 0.138449, -0.2, 1.23845, -0.138489, -0.138489, 0.961511, -0.2, -0.138489, 0.9, -0.138489, -0.138489, 0.9, 0.138449, -0.138489, 0.961511, 0.199961, -0.2, 1.23845, 0.138449, -0.138489, 1.3, -0.138489, -0.138489, 1.23845, -0.2, 0.138449, 0.961511, -0.2, 0.138449, 0.9, -0.138489, 0.138449, 0.9, 0.138449, 0.138449, 0.961511, 0.199961, -0.138489, 1.23845, 0.199961, -0.138489, 1.3, 0.138449, 0.138449, 1.3, -0.138489, 0.138449, 1.23845, -0.2, 0.199961, 0.961511, -0.138489, 0.199961, 0.961511, 0.138449, 0.138449, 1.23845, 0.199961, 0.138449, 1.3, 0.138449, 0.199961, 1.23845, -0.138489, 0.199961, 1.23845, 0.138449)
124
+
125
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_ye88r"]
126
+ points = PackedVector3Array(0.356386, 1.13939, -0.08, 0.35637, 1.07013, -0.04, 0.196386, 1.10475, -0.02, 0.196386, 1.13939, -0.04, 0.356386, 1.20868, -0.04, 0.356386, 1.13939, 0.08, 0.35637, 1.07013, 0.04, 0.196386, 1.10475, 0.02, 0.196386, 1.17404, -0.02, 0.356386, 1.20868, 0.04, 0.196386, 1.13939, 0.04, 0.196386, 1.17404, 0.02)
127
+
128
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_7x03l"]
129
+ points = PackedVector3Array(-0.356386, 1.13939, -0.08, -0.356386, 1.07013, -0.04, -0.356386, 1.20868, -0.04, -0.196386, 1.13939, -0.04, -0.196386, 1.10475, -0.02, -0.356386, 1.07013, 0.04, -0.356386, 1.20868, 0.04, -0.196386, 1.17404, -0.02, -0.196386, 1.10475, 0.02, -0.356386, 1.13939, 0.08, -0.196386, 1.17404, 0.02, -0.196386, 1.13939, 0.04)
130
+
131
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_sq7ka"]
132
+ points = PackedVector3Array(0.08, 1.13939, -0.356386, 0.04, 1.20868, -0.356386, 0.04, 1.13939, -0.196386, 0.02, 1.10475, -0.196386, 0.04, 1.07013, -0.356386, -0.04, 1.20868, -0.356386, 0.02, 1.17404, -0.196386, -0.02, 1.10475, -0.196386, -0.04, 1.07013, -0.356386, -0.08, 1.13939, -0.356386, -0.0400157, 1.13939, -0.196386, -0.02, 1.17404, -0.196386)
133
+
134
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_qs1wt"]
135
+ points = PackedVector3Array(0.08, 1.13939, 0.356386, 0.04, 1.20868, 0.356386, 0.04, 1.07013, 0.356386, 0.02, 1.10475, 0.196386, 0.04, 1.13939, 0.196386, 0.02, 1.17404, 0.196386, -0.04, 1.20868, 0.356386, -0.04, 1.07013, 0.356386, -0.02, 1.10475, 0.196386, -0.02, 1.17404, 0.196386, -0.0400157, 1.13939, 0.196386, -0.08, 1.13939, 0.356386)
136
+
137
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_clf7x"]
138
+ points = PackedVector3Array(0.689131, -0.327066, 1.10126, 0.72, -0.357841, 1.10126, 0.689131, -0.327066, 0.962799, -0.689272, -0.327066, 1.10126, 0.689131, -0.357841, 1.13204, 0.72, -0.357841, 0.962799, 0.72, -0.496311, 1.10126, -0.689272, -0.327066, 0.962799, -0.72, -0.357841, 1.10126, -0.689272, -0.357841, 1.13204, 0.689131, -0.496311, 1.13204, 0.72, -0.496311, 0.962799, 0.689131, -0.527066, 1.10126, -0.72, -0.357841, 0.962799, -0.72, -0.496311, 1.10126, -0.689272, -0.496311, 1.13204, 0.689131, -0.527066, 0.962799, -0.689272, -0.527066, 1.10126, -0.72, -0.496311, 0.962799, -0.689272, -0.527066, 0.962799)
139
+
140
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_jgccj"]
141
+ points = PackedVector3Array(-1.35457, -0.282196, -0.480807, -1.35457, -0.251478, -0.511552, -1.14268, -0.282196, -0.480807, -1.35457, -0.282196, -0.119275, -1.38532, -0.251478, -0.480807, -1.14268, -0.251478, -0.511552, -1.35457, 0.558711, -0.511552, -1.0818, -0.282196, 0.119175, -1.38532, -0.251478, -0.119275, -1.29369, -0.282196, 0.480707, -1.38532, 0.558711, -0.480807, -1.14268, 0.558711, -0.511552, -1.0818, -0.251478, 0.08843, -1.35457, 0.589429, -0.480807, -1.0818, -0.282196, 0.480707, -1.38532, 0.558711, -0.119275, -1.32444, -0.251478, 0.480707, -1.29369, -0.251478, 0.511552, -1.14268, 0.589429, -0.480807, -1.0818, 0.589514, 0.119175, -1.0818, 0.558711, 0.08843, -1.35457, 0.589429, -0.119275, -1.0818, -0.251478, 0.511552, -1.32444, 0.558711, 0.480707, -1.29369, 0.558711, 0.511552, -1.0818, 0.589514, 0.480707, -1.29369, 0.589429, 0.480707, -1.0818, 0.558711, 0.511552)
142
+
143
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_20jou"]
144
+ points = PackedVector3Array(0.689131, -0.205966, -0.915119, 0.72, -0.236737, -0.915119, 0.689131, -0.205966, -1.05359, -0.689272, -0.205966, -0.915136, -0.72, -0.236737, -0.915136, 0.689131, -0.527066, -0.915119, 0.72, -0.236737, -1.05359, 0.72, -0.496326, -0.915119, 0.689131, -0.236737, -1.08436, -0.689272, -0.205966, -1.05359, -0.72, -0.236737, -1.05359, -0.72, -0.496326, -0.915136, 0.689131, -0.527066, -1.05359, -0.689272, -0.527066, -0.915136, 0.72, -0.496326, -1.05359, 0.689131, -0.496326, -1.08436, -0.689272, -0.236737, -1.08436, -0.72, -0.496326, -1.05359, -0.689272, -0.527066, -1.05359, -0.689272, -0.496326, -1.08436)
145
+
146
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_y41en"]
147
+ points = PackedVector3Array(-4.35855, -4.80807, -1.43498, -4.05137, -5.11552, -1.43498, -4.35855, -4.80807, 0.683862, -4.35855, 1.19175, -2.0438, -4.05137, -5.11552, 0.683862, -4.05137, 0.8843, -2.0438, 4.05051, -5.11552, -1.43498, -4.05137, -4.80807, 0.991393, -4.35855, -1.19275, 0.683862, -4.35855, 4.80707, -2.0438, 4.05051, -5.11552, 0.683862, 4.05051, 0.8843, -2.0438, 4.35855, -4.80807, -1.43498, 4.05051, -4.80807, 0.991393, -4.05137, -1.19275, 0.991393, -4.35855, 4.80707, 0.0750408, -4.05137, 5.11552, -2.0438, 4.35855, -4.80807, 0.683862, 4.35855, 1.19175, -2.0438, 4.05051, -1.19275, 0.991393, -4.05137, 4.80707, 0.382571, -4.05137, 5.11552, 0.0750408, 4.05051, 5.11552, -2.0438, 4.35855, -1.19275, 0.683862, 4.35855, 4.80707, -2.0438, 4.05051, 4.80707, 0.382571, 4.05051, 5.11552, 0.0750408, 4.35855, 4.80707, 0.0750408)
148
+
149
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_23ttv"]
150
+ points = PackedVector3Array(-1.35526e-05, -0.0711111, 0.08, 0.0692685, -0.0711111, 0.04, -1.35526e-05, 0.0888889, 0.04, -0.0346546, 0.0888889, 0.02, -0.069282, -0.0711111, 0.04, 0.0692685, -0.0711111, -0.04, 0.0346275, 0.0888889, 0.02, -0.0346546, 0.0888889, -0.02, -0.069282, -0.0711111, -0.04, -1.35526e-05, -0.0711111, -0.08, 0.0346275, 0.0888889, -0.02, -1.35526e-05, 0.0888889, -0.04)
151
+
152
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_tgx77"]
153
+ points = PackedVector3Array(-1.35526e-05, -0.0711111, 0.08, 0.0692685, -0.0711111, 0.04, -1.35526e-05, 0.0888889, 0.04, -0.0346546, 0.0888889, 0.02, -0.069282, -0.0711111, 0.04, 0.0692685, -0.0711111, -0.04, 0.0346275, 0.0888889, 0.02, -0.0346546, 0.0888889, -0.02, -0.069282, -0.0711111, -0.04, -1.35526e-05, -0.0711111, -0.08, 0.0346275, 0.0888889, -0.02, -1.35526e-05, 0.0888889, -0.04)
154
+
155
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_bigji"]
156
+ points = PackedVector3Array(0.0523691, 0.0288044, 0.0994882, -0.0438545, -0.0191863, -0.175418, -0.0470589, -0.0235413, -0.141209, -0.176861, 0.0193378, -0.0165505, -0.105209, -0.0193862, 0.144003, 0.17542, -0.0191866, 0.0438551, 0.120067, 0.0191047, -0.136486, 0.0165505, 0.0193378, 0.176861, -0.0604779, 0.0192462, -0.17051, -0.170485, -0.0192497, -0.0604691, 0.170509, 0.019246, 0.0604775, 0.0604687, -0.0192496, 0.170484, 0.112025, -0.029344, -0.0373304, 0.136466, -0.0191083, -0.120049, -0.136486, 0.0191047, 0.120067, -0.112025, -0.029344, 0.0373304, -0.068293, 0.0288917, -0.094557, 0.112041, 0.029342, -0.0373358, -0.112041, 0.029342, 0.0373358, -0.144003, -0.0193862, 0.105209, 0.0682828, -0.0288938, 0.0945429, 0.176861, 0.0193378, 0.0165505, 0.0373304, -0.029344, -0.112025, -0.161776, 0.0195188, -0.072518, 0.072518, 0.0195188, 0.161776, 0.0373358, 0.029342, -0.112041, -0.0373304, -0.029344, 0.112025, -0.0373358, 0.029342, 0.112041, -0.0945432, -0.0288939, -0.068283, -0.0165485, -0.0193419, -0.176841, -0.0165505, 0.0193378, -0.176861, 0.105209, -0.0193862, -0.144003)
157
+
158
+ [sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_teqnf"]
159
+ points = PackedVector3Array(-0.199839, -0.531613, -0.02, -0.199839, -0.531613, 0.02, 0.161889, 0.544293, -0.02, -0.161929, -0.544293, -0.02, -0.161929, -0.544293, 0.02, 0.161889, 0.544293, 0.0199961, 0.199838, 0.531506, -0.02, 0.199838, 0.531506, 0.0199961)
160
+
161
+ [node name="Lander" type="Node3D" node_paths=PackedStringArray("raycast_sensor", "up_thruster", "left_thruster", "right_thruster", "forward_thruster", "back_thruster", "turn_left_thruster", "turn_right_thruster")]
162
+ script = ExtResource("1_2yq6u")
163
+ show_successful_landing_debug_text = true
164
+ up_thruster_max_force = 250.0
165
+ navigation_thruster_max_force = 25.0
166
+ raycast_sensor = NodePath("Lander/RayCastSensor3D")
167
+ up_thruster = NodePath("Lander/UpThruster")
168
+ left_thruster = NodePath("Lander/LeftThruster")
169
+ right_thruster = NodePath("Lander/RightThruster")
170
+ forward_thruster = NodePath("Lander/ForwardThruster")
171
+ back_thruster = NodePath("Lander/BackThruster")
172
+ turn_left_thruster = NodePath("Lander/TurnLeftThruster")
173
+ turn_right_thruster = NodePath("Lander/TurnRightThruster")
174
+
175
+ [node name="Lander" parent="." instance=ExtResource("2_s4oxe")]
176
+ collision_layer = 2
177
+ mass = 100.0
178
+ gravity_scale = 0.17
179
+ center_of_mass_mode = 1
180
+ continuous_cd = true
181
+ max_contacts_reported = 1
182
+ contact_monitor = true
183
+
184
+ [node name="UpThruster" parent="Lander" index="1"]
185
+ script = ExtResource("3_ylucp")
186
+
187
+ [node name="GPUParticles3D" type="GPUParticles3D" parent="Lander/UpThruster" index="0"]
188
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0847096, 0)
189
+ amount = 32
190
+ lifetime = 3.0
191
+ local_coords = true
192
+ process_material = SubResource("ParticleProcessMaterial_rsa34")
193
+ draw_pass_1 = SubResource("QuadMesh_u5of1")
194
+
195
+ [node name="LeftThruster" parent="Lander" index="3"]
196
+ script = ExtResource("3_ylucp")
197
+
198
+ [node name="GPUParticles3D" type="GPUParticles3D" parent="Lander/LeftThruster" index="0"]
199
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0847096, 0)
200
+ amount = 32
201
+ lifetime = 3.0
202
+ local_coords = true
203
+ process_material = SubResource("ParticleProcessMaterial_ot7am")
204
+ draw_pass_1 = SubResource("QuadMesh_u5of1")
205
+
206
+ [node name="RightThruster" parent="Lander" index="4"]
207
+ transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, -0.285275, 1.13941, 0)
208
+ script = ExtResource("3_ylucp")
209
+
210
+ [node name="GPUParticles3D" type="GPUParticles3D" parent="Lander/RightThruster" index="0"]
211
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0847096, 0)
212
+ amount = 32
213
+ lifetime = 3.0
214
+ local_coords = true
215
+ process_material = SubResource("ParticleProcessMaterial_3l3es")
216
+ draw_pass_1 = SubResource("QuadMesh_u5of1")
217
+
218
+ [node name="BackThruster" parent="Lander" index="5"]
219
+ script = ExtResource("3_ylucp")
220
+
221
+ [node name="GPUParticles3D" type="GPUParticles3D" parent="Lander/BackThruster" index="0"]
222
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0847096, 0)
223
+ amount = 32
224
+ lifetime = 3.0
225
+ local_coords = true
226
+ process_material = SubResource("ParticleProcessMaterial_k81u0")
227
+ draw_pass_1 = SubResource("QuadMesh_u5of1")
228
+
229
+ [node name="ForwardThruster" parent="Lander" index="6"]
230
+ transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 1.13941, 0.285275)
231
+ script = ExtResource("3_ylucp")
232
+
233
+ [node name="GPUParticles3D" type="GPUParticles3D" parent="Lander/ForwardThruster" index="0"]
234
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0847096, 0)
235
+ amount = 32
236
+ lifetime = 3.0
237
+ local_coords = true
238
+ process_material = SubResource("ParticleProcessMaterial_5yx2o")
239
+ draw_pass_1 = SubResource("QuadMesh_u5of1")
240
+
241
+ [node name="TurnLeftThruster" parent="Lander" index="11"]
242
+ script = ExtResource("3_ylucp")
243
+
244
+ [node name="GPUParticles3D" type="GPUParticles3D" parent="Lander/TurnLeftThruster" index="0"]
245
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0847096, 0)
246
+ amount = 16
247
+ local_coords = true
248
+ process_material = SubResource("ParticleProcessMaterial_pnaje")
249
+ draw_pass_1 = SubResource("QuadMesh_u5of1")
250
+
251
+ [node name="TurnRightThruster" parent="Lander" index="12"]
252
+ script = ExtResource("3_ylucp")
253
+
254
+ [node name="GPUParticles3D" type="GPUParticles3D" parent="Lander/TurnRightThruster" index="0"]
255
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0847096, 0)
256
+ amount = 16
257
+ local_coords = true
258
+ process_material = SubResource("ParticleProcessMaterial_krfta")
259
+ draw_pass_1 = SubResource("QuadMesh_u5of1")
260
+
261
+ [node name="CollisionShape3D" type="CollisionShape3D" parent="Lander"]
262
+ shape = SubResource("ConvexPolygonShape3D_tvjil")
263
+
264
+ [node name="CollisionShape3D2" type="CollisionShape3D" parent="Lander"]
265
+ shape = SubResource("ConvexPolygonShape3D_oxrum")
266
+
267
+ [node name="CollisionShape3D3" type="CollisionShape3D" parent="Lander"]
268
+ shape = SubResource("ConvexPolygonShape3D_hn0x3")
269
+
270
+ [node name="CollisionShape3D4" type="CollisionShape3D" parent="Lander"]
271
+ shape = SubResource("ConvexPolygonShape3D_ye88r")
272
+
273
+ [node name="CollisionShape3D5" type="CollisionShape3D" parent="Lander"]
274
+ shape = SubResource("ConvexPolygonShape3D_7x03l")
275
+
276
+ [node name="CollisionShape3D6" type="CollisionShape3D" parent="Lander"]
277
+ shape = SubResource("ConvexPolygonShape3D_sq7ka")
278
+
279
+ [node name="CollisionShape3D7" type="CollisionShape3D" parent="Lander"]
280
+ shape = SubResource("ConvexPolygonShape3D_qs1wt")
281
+
282
+ [node name="CollisionShape3D8" type="CollisionShape3D" parent="Lander"]
283
+ shape = SubResource("ConvexPolygonShape3D_clf7x")
284
+
285
+ [node name="CollisionShape3D9" type="CollisionShape3D" parent="Lander"]
286
+ shape = SubResource("ConvexPolygonShape3D_jgccj")
287
+
288
+ [node name="CollisionShape3D10" type="CollisionShape3D" parent="Lander"]
289
+ shape = SubResource("ConvexPolygonShape3D_20jou")
290
+
291
+ [node name="CollisionShape3D11" type="CollisionShape3D" parent="Lander"]
292
+ transform = Transform3D(0, 0, 0.1, 0.1, 0, 0, 0, 0.1, 0, 1.28615, 0.153659, 0)
293
+ shape = SubResource("ConvexPolygonShape3D_y41en")
294
+
295
+ [node name="CollisionShape3D12" type="CollisionShape3D" parent="Lander"]
296
+ transform = Transform3D(5.96046e-08, -0.707107, -0.707107, 1, 0, 2.98023e-08, -2.98023e-08, -0.707107, 0.707107, 1.13648, 0, -0.876737)
297
+ shape = SubResource("ConvexPolygonShape3D_23ttv")
298
+
299
+ [node name="CollisionShape3D13" type="CollisionShape3D" parent="Lander"]
300
+ transform = Transform3D(5.96046e-08, -0.707107, -0.707107, 1, 0, 2.98023e-08, -2.98023e-08, -0.707107, 0.707107, -1.13648, 0, 0.876737)
301
+ shape = SubResource("ConvexPolygonShape3D_tgx77")
302
+
303
+ [node name="RayCastSensor3D" type="Node3D" parent="Lander"]
304
+ transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0)
305
+ script = ExtResource("6_03nxx")
306
+ n_rays_width = 12.0
307
+ n_rays_height = 12.0
308
+ ray_length = 250.0
309
+ cone_width = 360.0
310
+ cone_height = 360.0
311
+
312
+ [node name="node_0 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
313
+ target_position = Vector3(62.5, -64.7048, 233.253)
314
+
315
+ [node name="node_0 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
316
+ target_position = Vector3(45.7532, -176.777, 170.753)
317
+
318
+ [node name="node_0 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
319
+ target_position = Vector3(16.7468, -241.481, 62.5)
320
+
321
+ [node name="node_0 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
322
+ target_position = Vector3(-16.7468, -241.481, -62.5)
323
+
324
+ [node name="node_0 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
325
+ target_position = Vector3(-45.7532, -176.777, -170.753)
326
+
327
+ [node name="node_0 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
328
+ target_position = Vector3(-62.5, -64.7048, -233.253)
329
+
330
+ [node name="node_0 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
331
+ target_position = Vector3(-62.5, 64.7048, -233.253)
332
+
333
+ [node name="@RayCast3D@31274" type="RayCast3D" parent="Lander/RayCastSensor3D"]
334
+ target_position = Vector3(-45.7532, 176.777, -170.753)
335
+
336
+ [node name="@RayCast3D@31275" type="RayCast3D" parent="Lander/RayCastSensor3D"]
337
+ target_position = Vector3(-16.7468, 241.481, -62.5)
338
+
339
+ [node name="@RayCast3D@31276" type="RayCast3D" parent="Lander/RayCastSensor3D"]
340
+ target_position = Vector3(16.7468, 241.481, 62.5)
341
+
342
+ [node name="@RayCast3D@31277" type="RayCast3D" parent="Lander/RayCastSensor3D"]
343
+ target_position = Vector3(45.7532, 176.777, 170.753)
344
+
345
+ [node name="@RayCast3D@31278" type="RayCast3D" parent="Lander/RayCastSensor3D"]
346
+ target_position = Vector3(62.5, 64.7048, 233.253)
347
+
348
+ [node name="node_1 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
349
+ target_position = Vector3(170.753, -64.7048, 170.753)
350
+
351
+ [node name="node_1 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
352
+ target_position = Vector3(125, -176.777, 125)
353
+
354
+ [node name="node_1 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
355
+ target_position = Vector3(45.7532, -241.481, 45.7532)
356
+
357
+ [node name="node_1 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
358
+ target_position = Vector3(-45.7532, -241.481, -45.7532)
359
+
360
+ [node name="node_1 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
361
+ target_position = Vector3(-125, -176.777, -125)
362
+
363
+ [node name="node_1 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
364
+ target_position = Vector3(-170.753, -64.7048, -170.753)
365
+
366
+ [node name="node_1 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
367
+ target_position = Vector3(-170.753, 64.7048, -170.753)
368
+
369
+ [node name="@RayCast3D@31279" type="RayCast3D" parent="Lander/RayCastSensor3D"]
370
+ target_position = Vector3(-125, 176.777, -125)
371
+
372
+ [node name="@RayCast3D@31280" type="RayCast3D" parent="Lander/RayCastSensor3D"]
373
+ target_position = Vector3(-45.7532, 241.481, -45.7532)
374
+
375
+ [node name="@RayCast3D@31281" type="RayCast3D" parent="Lander/RayCastSensor3D"]
376
+ target_position = Vector3(45.7532, 241.481, 45.7532)
377
+
378
+ [node name="@RayCast3D@31282" type="RayCast3D" parent="Lander/RayCastSensor3D"]
379
+ target_position = Vector3(125, 176.777, 125)
380
+
381
+ [node name="@RayCast3D@31283" type="RayCast3D" parent="Lander/RayCastSensor3D"]
382
+ target_position = Vector3(170.753, 64.7048, 170.753)
383
+
384
+ [node name="node_2 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
385
+ target_position = Vector3(233.253, -64.7048, 62.5)
386
+
387
+ [node name="node_2 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
388
+ target_position = Vector3(170.753, -176.777, 45.7532)
389
+
390
+ [node name="node_2 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
391
+ target_position = Vector3(62.5, -241.481, 16.7468)
392
+
393
+ [node name="node_2 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
394
+ target_position = Vector3(-62.5, -241.481, -16.7468)
395
+
396
+ [node name="node_2 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
397
+ target_position = Vector3(-170.753, -176.777, -45.7532)
398
+
399
+ [node name="node_2 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
400
+ target_position = Vector3(-233.253, -64.7048, -62.5)
401
+
402
+ [node name="node_2 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
403
+ target_position = Vector3(-233.253, 64.7048, -62.5)
404
+
405
+ [node name="@RayCast3D@31284" type="RayCast3D" parent="Lander/RayCastSensor3D"]
406
+ target_position = Vector3(-170.753, 176.777, -45.7532)
407
+
408
+ [node name="@RayCast3D@31285" type="RayCast3D" parent="Lander/RayCastSensor3D"]
409
+ target_position = Vector3(-62.5, 241.481, -16.7468)
410
+
411
+ [node name="@RayCast3D@31286" type="RayCast3D" parent="Lander/RayCastSensor3D"]
412
+ target_position = Vector3(62.5, 241.481, 16.7468)
413
+
414
+ [node name="@RayCast3D@31287" type="RayCast3D" parent="Lander/RayCastSensor3D"]
415
+ target_position = Vector3(170.753, 176.777, 45.7532)
416
+
417
+ [node name="@RayCast3D@31288" type="RayCast3D" parent="Lander/RayCastSensor3D"]
418
+ target_position = Vector3(233.253, 64.7048, 62.5)
419
+
420
+ [node name="node_3 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
421
+ target_position = Vector3(233.253, -64.7048, -62.5)
422
+
423
+ [node name="node_3 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
424
+ target_position = Vector3(170.753, -176.777, -45.7532)
425
+
426
+ [node name="node_3 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
427
+ target_position = Vector3(62.5, -241.481, -16.7468)
428
+
429
+ [node name="node_3 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
430
+ target_position = Vector3(-62.5, -241.481, 16.7468)
431
+
432
+ [node name="node_3 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
433
+ target_position = Vector3(-170.753, -176.777, 45.7532)
434
+
435
+ [node name="node_3 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
436
+ target_position = Vector3(-233.253, -64.7048, 62.5)
437
+
438
+ [node name="node_3 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
439
+ target_position = Vector3(-233.253, 64.7048, 62.5)
440
+
441
+ [node name="@RayCast3D@31289" type="RayCast3D" parent="Lander/RayCastSensor3D"]
442
+ target_position = Vector3(-170.753, 176.777, 45.7532)
443
+
444
+ [node name="@RayCast3D@31290" type="RayCast3D" parent="Lander/RayCastSensor3D"]
445
+ target_position = Vector3(-62.5, 241.481, 16.7468)
446
+
447
+ [node name="@RayCast3D@31291" type="RayCast3D" parent="Lander/RayCastSensor3D"]
448
+ target_position = Vector3(62.5, 241.481, -16.7468)
449
+
450
+ [node name="@RayCast3D@31292" type="RayCast3D" parent="Lander/RayCastSensor3D"]
451
+ target_position = Vector3(170.753, 176.777, -45.7532)
452
+
453
+ [node name="@RayCast3D@31293" type="RayCast3D" parent="Lander/RayCastSensor3D"]
454
+ target_position = Vector3(233.253, 64.7048, -62.5)
455
+
456
+ [node name="node_4 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
457
+ target_position = Vector3(170.753, -64.7048, -170.753)
458
+
459
+ [node name="node_4 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
460
+ target_position = Vector3(125, -176.777, -125)
461
+
462
+ [node name="node_4 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
463
+ target_position = Vector3(45.7532, -241.481, -45.7532)
464
+
465
+ [node name="node_4 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
466
+ target_position = Vector3(-45.7532, -241.481, 45.7532)
467
+
468
+ [node name="node_4 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
469
+ target_position = Vector3(-125, -176.777, 125)
470
+
471
+ [node name="node_4 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
472
+ target_position = Vector3(-170.753, -64.7048, 170.753)
473
+
474
+ [node name="node_4 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
475
+ target_position = Vector3(-170.753, 64.7048, 170.753)
476
+
477
+ [node name="@RayCast3D@31294" type="RayCast3D" parent="Lander/RayCastSensor3D"]
478
+ target_position = Vector3(-125, 176.777, 125)
479
+
480
+ [node name="@RayCast3D@31295" type="RayCast3D" parent="Lander/RayCastSensor3D"]
481
+ target_position = Vector3(-45.7532, 241.481, 45.7532)
482
+
483
+ [node name="@RayCast3D@31296" type="RayCast3D" parent="Lander/RayCastSensor3D"]
484
+ target_position = Vector3(45.7532, 241.481, -45.7532)
485
+
486
+ [node name="@RayCast3D@31297" type="RayCast3D" parent="Lander/RayCastSensor3D"]
487
+ target_position = Vector3(125, 176.777, -125)
488
+
489
+ [node name="@RayCast3D@31298" type="RayCast3D" parent="Lander/RayCastSensor3D"]
490
+ target_position = Vector3(170.753, 64.7048, -170.753)
491
+
492
+ [node name="node_5 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
493
+ target_position = Vector3(62.5, -64.7048, -233.253)
494
+
495
+ [node name="node_5 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
496
+ target_position = Vector3(45.7532, -176.777, -170.753)
497
+
498
+ [node name="node_5 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
499
+ target_position = Vector3(16.7468, -241.481, -62.5)
500
+
501
+ [node name="node_5 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
502
+ target_position = Vector3(-16.7468, -241.481, 62.5)
503
+
504
+ [node name="node_5 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
505
+ target_position = Vector3(-45.7532, -176.777, 170.753)
506
+
507
+ [node name="node_5 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
508
+ target_position = Vector3(-62.5, -64.7048, 233.253)
509
+
510
+ [node name="node_5 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
511
+ target_position = Vector3(-62.5, 64.7048, 233.253)
512
+
513
+ [node name="@RayCast3D@31299" type="RayCast3D" parent="Lander/RayCastSensor3D"]
514
+ target_position = Vector3(-45.7532, 176.777, 170.753)
515
+
516
+ [node name="@RayCast3D@31300" type="RayCast3D" parent="Lander/RayCastSensor3D"]
517
+ target_position = Vector3(-16.7468, 241.481, 62.5)
518
+
519
+ [node name="@RayCast3D@31301" type="RayCast3D" parent="Lander/RayCastSensor3D"]
520
+ target_position = Vector3(16.7468, 241.481, -62.5)
521
+
522
+ [node name="@RayCast3D@31302" type="RayCast3D" parent="Lander/RayCastSensor3D"]
523
+ target_position = Vector3(45.7532, 176.777, -170.753)
524
+
525
+ [node name="@RayCast3D@31303" type="RayCast3D" parent="Lander/RayCastSensor3D"]
526
+ target_position = Vector3(62.5, 64.7048, -233.253)
527
+
528
+ [node name="@RayCast3D@31304" type="RayCast3D" parent="Lander/RayCastSensor3D"]
529
+ target_position = Vector3(-62.5, -64.7048, -233.253)
530
+
531
+ [node name="@RayCast3D@31305" type="RayCast3D" parent="Lander/RayCastSensor3D"]
532
+ target_position = Vector3(-45.7532, -176.777, -170.753)
533
+
534
+ [node name="@RayCast3D@31306" type="RayCast3D" parent="Lander/RayCastSensor3D"]
535
+ target_position = Vector3(-16.7468, -241.481, -62.5)
536
+
537
+ [node name="@RayCast3D@31307" type="RayCast3D" parent="Lander/RayCastSensor3D"]
538
+ target_position = Vector3(16.7468, -241.481, 62.5)
539
+
540
+ [node name="@RayCast3D@31308" type="RayCast3D" parent="Lander/RayCastSensor3D"]
541
+ target_position = Vector3(45.7532, -176.777, 170.753)
542
+
543
+ [node name="@RayCast3D@31309" type="RayCast3D" parent="Lander/RayCastSensor3D"]
544
+ target_position = Vector3(62.5, -64.7048, 233.253)
545
+
546
+ [node name="node_6 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
547
+ target_position = Vector3(62.5, 64.7048, 233.253)
548
+
549
+ [node name="@RayCast3D@31310" type="RayCast3D" parent="Lander/RayCastSensor3D"]
550
+ target_position = Vector3(45.7532, 176.777, 170.753)
551
+
552
+ [node name="@RayCast3D@31311" type="RayCast3D" parent="Lander/RayCastSensor3D"]
553
+ target_position = Vector3(16.7468, 241.481, 62.5)
554
+
555
+ [node name="@RayCast3D@31312" type="RayCast3D" parent="Lander/RayCastSensor3D"]
556
+ target_position = Vector3(-16.7468, 241.481, -62.5)
557
+
558
+ [node name="@RayCast3D@31313" type="RayCast3D" parent="Lander/RayCastSensor3D"]
559
+ target_position = Vector3(-45.7532, 176.777, -170.753)
560
+
561
+ [node name="@RayCast3D@31314" type="RayCast3D" parent="Lander/RayCastSensor3D"]
562
+ target_position = Vector3(-62.5, 64.7048, -233.253)
563
+
564
+ [node name="@RayCast3D@31315" type="RayCast3D" parent="Lander/RayCastSensor3D"]
565
+ target_position = Vector3(-170.753, -64.7048, -170.753)
566
+
567
+ [node name="@RayCast3D@31316" type="RayCast3D" parent="Lander/RayCastSensor3D"]
568
+ target_position = Vector3(-125, -176.777, -125)
569
+
570
+ [node name="@RayCast3D@31317" type="RayCast3D" parent="Lander/RayCastSensor3D"]
571
+ target_position = Vector3(-45.7532, -241.481, -45.7532)
572
+
573
+ [node name="@RayCast3D@31318" type="RayCast3D" parent="Lander/RayCastSensor3D"]
574
+ target_position = Vector3(45.7532, -241.481, 45.7532)
575
+
576
+ [node name="@RayCast3D@31319" type="RayCast3D" parent="Lander/RayCastSensor3D"]
577
+ target_position = Vector3(125, -176.777, 125)
578
+
579
+ [node name="@RayCast3D@31320" type="RayCast3D" parent="Lander/RayCastSensor3D"]
580
+ target_position = Vector3(170.753, -64.7048, 170.753)
581
+
582
+ [node name="@RayCast3D@31321" type="RayCast3D" parent="Lander/RayCastSensor3D"]
583
+ target_position = Vector3(170.753, 64.7048, 170.753)
584
+
585
+ [node name="@RayCast3D@31322" type="RayCast3D" parent="Lander/RayCastSensor3D"]
586
+ target_position = Vector3(125, 176.777, 125)
587
+
588
+ [node name="@RayCast3D@31323" type="RayCast3D" parent="Lander/RayCastSensor3D"]
589
+ target_position = Vector3(45.7532, 241.481, 45.7532)
590
+
591
+ [node name="@RayCast3D@31324" type="RayCast3D" parent="Lander/RayCastSensor3D"]
592
+ target_position = Vector3(-45.7532, 241.481, -45.7532)
593
+
594
+ [node name="@RayCast3D@31325" type="RayCast3D" parent="Lander/RayCastSensor3D"]
595
+ target_position = Vector3(-125, 176.777, -125)
596
+
597
+ [node name="@RayCast3D@31326" type="RayCast3D" parent="Lander/RayCastSensor3D"]
598
+ target_position = Vector3(-170.753, 64.7048, -170.753)
599
+
600
+ [node name="node_8 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
601
+ target_position = Vector3(-233.253, -64.7048, -62.5)
602
+
603
+ [node name="node_8 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
604
+ target_position = Vector3(-170.753, -176.777, -45.7532)
605
+
606
+ [node name="node_8 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
607
+ target_position = Vector3(-62.5, -241.481, -16.7468)
608
+
609
+ [node name="node_8 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
610
+ target_position = Vector3(62.5, -241.481, 16.7468)
611
+
612
+ [node name="node_8 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
613
+ target_position = Vector3(170.753, -176.777, 45.7532)
614
+
615
+ [node name="node_8 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
616
+ target_position = Vector3(233.253, -64.7048, 62.5)
617
+
618
+ [node name="node_8 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
619
+ target_position = Vector3(233.253, 64.7048, 62.5)
620
+
621
+ [node name="@RayCast3D@31327" type="RayCast3D" parent="Lander/RayCastSensor3D"]
622
+ target_position = Vector3(170.753, 176.777, 45.7532)
623
+
624
+ [node name="@RayCast3D@31328" type="RayCast3D" parent="Lander/RayCastSensor3D"]
625
+ target_position = Vector3(62.5, 241.481, 16.7468)
626
+
627
+ [node name="@RayCast3D@31329" type="RayCast3D" parent="Lander/RayCastSensor3D"]
628
+ target_position = Vector3(-62.5, 241.481, -16.7468)
629
+
630
+ [node name="@RayCast3D@31330" type="RayCast3D" parent="Lander/RayCastSensor3D"]
631
+ target_position = Vector3(-170.753, 176.777, -45.7532)
632
+
633
+ [node name="@RayCast3D@31331" type="RayCast3D" parent="Lander/RayCastSensor3D"]
634
+ target_position = Vector3(-233.253, 64.7048, -62.5)
635
+
636
+ [node name="@RayCast3D@31332" type="RayCast3D" parent="Lander/RayCastSensor3D"]
637
+ target_position = Vector3(-233.253, -64.7048, 62.5)
638
+
639
+ [node name="@RayCast3D@31333" type="RayCast3D" parent="Lander/RayCastSensor3D"]
640
+ target_position = Vector3(-170.753, -176.777, 45.7532)
641
+
642
+ [node name="@RayCast3D@31334" type="RayCast3D" parent="Lander/RayCastSensor3D"]
643
+ target_position = Vector3(-62.5, -241.481, 16.7468)
644
+
645
+ [node name="@RayCast3D@31335" type="RayCast3D" parent="Lander/RayCastSensor3D"]
646
+ target_position = Vector3(62.5, -241.481, -16.7468)
647
+
648
+ [node name="@RayCast3D@31336" type="RayCast3D" parent="Lander/RayCastSensor3D"]
649
+ target_position = Vector3(170.753, -176.777, -45.7532)
650
+
651
+ [node name="@RayCast3D@31337" type="RayCast3D" parent="Lander/RayCastSensor3D"]
652
+ target_position = Vector3(233.253, -64.7048, -62.5)
653
+
654
+ [node name="@RayCast3D@31338" type="RayCast3D" parent="Lander/RayCastSensor3D"]
655
+ target_position = Vector3(233.253, 64.7048, -62.5)
656
+
657
+ [node name="@RayCast3D@31339" type="RayCast3D" parent="Lander/RayCastSensor3D"]
658
+ target_position = Vector3(170.753, 176.777, -45.7532)
659
+
660
+ [node name="@RayCast3D@31340" type="RayCast3D" parent="Lander/RayCastSensor3D"]
661
+ target_position = Vector3(62.5, 241.481, -16.7468)
662
+
663
+ [node name="@RayCast3D@31341" type="RayCast3D" parent="Lander/RayCastSensor3D"]
664
+ target_position = Vector3(-62.5, 241.481, 16.7468)
665
+
666
+ [node name="@RayCast3D@31342" type="RayCast3D" parent="Lander/RayCastSensor3D"]
667
+ target_position = Vector3(-170.753, 176.777, 45.7532)
668
+
669
+ [node name="@RayCast3D@31343" type="RayCast3D" parent="Lander/RayCastSensor3D"]
670
+ target_position = Vector3(-233.253, 64.7048, 62.5)
671
+
672
+ [node name="node_10 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
673
+ target_position = Vector3(-170.753, -64.7048, 170.753)
674
+
675
+ [node name="node_10 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
676
+ target_position = Vector3(-125, -176.777, 125)
677
+
678
+ [node name="node_10 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
679
+ target_position = Vector3(-45.7532, -241.481, 45.7532)
680
+
681
+ [node name="node_10 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
682
+ target_position = Vector3(45.7532, -241.481, -45.7532)
683
+
684
+ [node name="node_10 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
685
+ target_position = Vector3(125, -176.777, -125)
686
+
687
+ [node name="node_10 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
688
+ target_position = Vector3(170.753, -64.7048, -170.753)
689
+
690
+ [node name="node_10 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
691
+ target_position = Vector3(170.753, 64.7048, -170.753)
692
+
693
+ [node name="node_10 7" type="RayCast3D" parent="Lander/RayCastSensor3D"]
694
+ target_position = Vector3(125, 176.777, -125)
695
+
696
+ [node name="node_10 8" type="RayCast3D" parent="Lander/RayCastSensor3D"]
697
+ target_position = Vector3(45.7532, 241.481, -45.7532)
698
+
699
+ [node name="node_10 9" type="RayCast3D" parent="Lander/RayCastSensor3D"]
700
+ target_position = Vector3(-45.7532, 241.481, 45.7532)
701
+
702
+ [node name="@RayCast3D@31344" type="RayCast3D" parent="Lander/RayCastSensor3D"]
703
+ target_position = Vector3(-125, 176.777, 125)
704
+
705
+ [node name="@RayCast3D@31345" type="RayCast3D" parent="Lander/RayCastSensor3D"]
706
+ target_position = Vector3(-170.753, 64.7048, 170.753)
707
+
708
+ [node name="node_11 0" type="RayCast3D" parent="Lander/RayCastSensor3D"]
709
+ target_position = Vector3(-62.5, -64.7048, 233.253)
710
+
711
+ [node name="node_11 1" type="RayCast3D" parent="Lander/RayCastSensor3D"]
712
+ target_position = Vector3(-45.7532, -176.777, 170.753)
713
+
714
+ [node name="node_11 2" type="RayCast3D" parent="Lander/RayCastSensor3D"]
715
+ target_position = Vector3(-16.7468, -241.481, 62.5)
716
+
717
+ [node name="node_11 3" type="RayCast3D" parent="Lander/RayCastSensor3D"]
718
+ target_position = Vector3(16.7468, -241.481, -62.5)
719
+
720
+ [node name="node_11 4" type="RayCast3D" parent="Lander/RayCastSensor3D"]
721
+ target_position = Vector3(45.7532, -176.777, -170.753)
722
+
723
+ [node name="node_11 5" type="RayCast3D" parent="Lander/RayCastSensor3D"]
724
+ target_position = Vector3(62.5, -64.7048, -233.253)
725
+
726
+ [node name="node_11 6" type="RayCast3D" parent="Lander/RayCastSensor3D"]
727
+ target_position = Vector3(62.5, 64.7048, -233.253)
728
+
729
+ [node name="node_11 7" type="RayCast3D" parent="Lander/RayCastSensor3D"]
730
+ target_position = Vector3(45.7532, 176.777, -170.753)
731
+
732
+ [node name="node_11 8" type="RayCast3D" parent="Lander/RayCastSensor3D"]
733
+ target_position = Vector3(16.7468, 241.481, -62.5)
734
+
735
+ [node name="node_11 9" type="RayCast3D" parent="Lander/RayCastSensor3D"]
736
+ target_position = Vector3(-16.7468, 241.481, 62.5)
737
+
738
+ [node name="@RayCast3D@31346" type="RayCast3D" parent="Lander/RayCastSensor3D"]
739
+ target_position = Vector3(-45.7532, 176.777, 170.753)
740
+
741
+ [node name="@RayCast3D@31347" type="RayCast3D" parent="Lander/RayCastSensor3D"]
742
+ target_position = Vector3(-62.5, 64.7048, 233.253)
743
+
744
+ [node name="LandingLeg" parent="." instance=ExtResource("4_gp4fc")]
745
+ collision_layer = 2
746
+ gravity_scale = 0.17
747
+ center_of_mass_mode = 1
748
+ center_of_mass = Vector3(-1.17917, -1.72518, 1.02244)
749
+ continuous_cd = true
750
+ max_contacts_reported = 1
751
+ contact_monitor = true
752
+
753
+ [node name="CollisionShape3D" type="CollisionShape3D" parent="LandingLeg"]
754
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.17917, -1.72518, 1.02244)
755
+ shape = SubResource("ConvexPolygonShape3D_bigji")
756
+
757
+ [node name="CollisionShape3D2" type="CollisionShape3D" parent="LandingLeg"]
758
+ transform = Transform3D(0.707107, 0, 0.707107, 0, 1, 0, -0.707107, 0, 0.707107, -1.05984, -1.20306, 0.903108)
759
+ shape = SubResource("ConvexPolygonShape3D_teqnf")
760
+
761
+ [node name="LandingLeg2" parent="." instance=ExtResource("4_gp4fc")]
762
+ collision_layer = 2
763
+ gravity_scale = 0.17
764
+ center_of_mass_mode = 1
765
+ center_of_mass = Vector3(-1.179, -1.725, -1.022)
766
+ continuous_cd = true
767
+ max_contacts_reported = 1
768
+ contact_monitor = true
769
+
770
+ [node name="Leg" parent="LandingLeg2" index="0"]
771
+ transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -1.179, -1.725, -1.022)
772
+
773
+ [node name="CollisionShape3D" type="CollisionShape3D" parent="LandingLeg2"]
774
+ transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -1.179, -1.725, -1.022)
775
+ shape = SubResource("ConvexPolygonShape3D_bigji")
776
+
777
+ [node name="CollisionShape3D2" type="CollisionShape3D" parent="LandingLeg2"]
778
+ transform = Transform3D(0.707107, 0, -0.707107, 0, 1, 0, 0.707107, 0, 0.707107, -1.05967, -1.20288, -0.902668)
779
+ shape = SubResource("ConvexPolygonShape3D_teqnf")
780
+
781
+ [node name="LandingLeg3" parent="." instance=ExtResource("4_gp4fc")]
782
+ collision_layer = 2
783
+ gravity_scale = 0.17
784
+ center_of_mass_mode = 1
785
+ center_of_mass = Vector3(1.179, -1.725, 1.022)
786
+ continuous_cd = true
787
+ max_contacts_reported = 1
788
+ contact_monitor = true
789
+
790
+ [node name="Leg" parent="LandingLeg3" index="0"]
791
+ transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 1.179, -1.725, 1.022)
792
+
793
+ [node name="CollisionShape3D" type="CollisionShape3D" parent="LandingLeg3"]
794
+ transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 1.179, -1.725, 1.022)
795
+ shape = SubResource("ConvexPolygonShape3D_bigji")
796
+
797
+ [node name="CollisionShape3D2" type="CollisionShape3D" parent="LandingLeg3"]
798
+ transform = Transform3D(-0.707107, 0, 0.707107, 0, 1, 0, -0.707107, 0, -0.707107, 1.05967, -1.20288, 0.902668)
799
+ shape = SubResource("ConvexPolygonShape3D_teqnf")
800
+
801
+ [node name="LandingLeg4" parent="." instance=ExtResource("4_gp4fc")]
802
+ collision_layer = 2
803
+ gravity_scale = 0.17
804
+ center_of_mass_mode = 1
805
+ center_of_mass = Vector3(1.179, -1.725, -1.022)
806
+ continuous_cd = true
807
+ max_contacts_reported = 1
808
+ contact_monitor = true
809
+
810
+ [node name="Leg" parent="LandingLeg4" index="0"]
811
+ transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 1.179, -1.725, -1.022)
812
+
813
+ [node name="CollisionShape3D" type="CollisionShape3D" parent="LandingLeg4"]
814
+ transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 1.179, -1.725, -1.022)
815
+ shape = SubResource("ConvexPolygonShape3D_bigji")
816
+
817
+ [node name="CollisionShape3D2" type="CollisionShape3D" parent="LandingLeg4"]
818
+ transform = Transform3D(-0.707107, 0, -0.707107, 0, 1, 0, 0.707107, 0, -0.707107, 1.05967, -1.20288, -0.902671)
819
+ shape = SubResource("ConvexPolygonShape3D_teqnf")
820
+
821
+ [node name="Generic6DOFJoint3D" type="Generic6DOFJoint3D" parent="."]
822
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.17917, -1.72518, 1.02244)
823
+ node_a = NodePath("../Lander")
824
+ node_b = NodePath("../LandingLeg")
825
+ linear_limit_y/softness = 0.3
826
+ linear_limit_y/restitution = 0.01
827
+ linear_limit_y/damping = 0.06
828
+
829
+ [node name="Generic6DOFJoint3D2" type="Generic6DOFJoint3D" parent="."]
830
+ transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -1.179, -1.725, -1.022)
831
+ node_a = NodePath("../Lander")
832
+ node_b = NodePath("../LandingLeg2")
833
+ linear_limit_y/softness = 0.3
834
+ linear_limit_y/restitution = 0.01
835
+ linear_limit_y/damping = 0.06
836
+
837
+ [node name="Generic6DOFJoint3D3" type="Generic6DOFJoint3D" parent="."]
838
+ transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 1.179, -1.725, 1.022)
839
+ node_a = NodePath("../Lander")
840
+ node_b = NodePath("../LandingLeg3")
841
+ linear_limit_y/softness = 0.3
842
+ linear_limit_y/restitution = 0.01
843
+ linear_limit_y/damping = 0.06
844
+
845
+ [node name="Generic6DOFJoint3D4" type="Generic6DOFJoint3D" parent="."]
846
+ transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 1.179, -1.725, -1.022)
847
+ node_a = NodePath("../Lander")
848
+ node_b = NodePath("../LandingLeg4")
849
+ linear_limit_y/softness = 0.3
850
+ linear_limit_y/restitution = 0.01
851
+ linear_limit_y/damping = 0.06
852
+
853
+ [node name="AIController3D" type="Node3D" parent="."]
854
+ script = ExtResource("5_w0bd1")
855
+ reset_after = 6000
856
+
857
+ [connection signal="body_entered" from="Lander" to="." method="_on_lander_body_entered"]
858
+ [connection signal="body_entered" from="LandingLeg" to="." method="_on_landing_leg_body_entered"]
859
+ [connection signal="body_exited" from="LandingLeg" to="." method="_on_landing_leg_body_exited"]
860
+ [connection signal="body_entered" from="LandingLeg2" to="." method="_on_landing_leg_body_entered"]
861
+ [connection signal="body_exited" from="LandingLeg2" to="." method="_on_landing_leg_body_exited"]
862
+ [connection signal="body_entered" from="LandingLeg3" to="." method="_on_landing_leg_body_entered"]
863
+ [connection signal="body_exited" from="LandingLeg3" to="." method="_on_landing_leg_body_exited"]
864
+ [connection signal="body_entered" from="LandingLeg4" to="." method="_on_landing_leg_body_entered"]
865
+ [connection signal="body_exited" from="LandingLeg4" to="." method="_on_landing_leg_body_exited"]
866
+
867
+ [editable path="Lander"]
868
+ [editable path="LandingLeg"]
869
+ [editable path="LandingLeg2"]
870
+ [editable path="LandingLeg3"]
871
+ [editable path="LandingLeg4"]
scenes/game_scene/LanderAIController3D.gd ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends AIController3D
2
+ class_name LanderAIController
3
+
4
+ ## AIController for the Lander. Handles the action definitions, actions, observations,
5
+ ## passes the rewards and resets the episode on timeout.
6
+
7
+ func get_obs() -> Dictionary:
8
+ _player = _player as Lander
9
+
10
+ # Positions and velocities are converted to the player's frame of reference
11
+ var player_velocity = _player.get_velocity_in_player_reference() / 50.0
12
+ var player_angular_velocity = _player.get_angular_velocity_in_player_reference() / 10.0
13
+
14
+ var observations : Array = [
15
+ n_steps / float(reset_after),
16
+ player_velocity.x,
17
+ player_velocity.y,
18
+ player_velocity.z,
19
+ player_angular_velocity.x,
20
+ player_angular_velocity.y,
21
+ player_angular_velocity.z,
22
+ _player._legs_in_contact_with_ground / 4.0
23
+ ]
24
+
25
+ observations.append_array(_player.get_orientation_as_array())
26
+
27
+ # After the first reset, the landing position will be assigned
28
+ if _player.times_restarted == 0:
29
+ observations.append_array([0.0, 0.0, 0.0, 0.0])
30
+ else:
31
+ var goal_position: Vector3 = (
32
+ _player.get_goal_position_in_player_reference()
33
+ )
34
+ observations.append_array(
35
+ [
36
+ goal_position.x,
37
+ goal_position.y,
38
+ goal_position.z,
39
+ _player.get_player_goal_direction_difference()
40
+ ]
41
+ )
42
+ observations.append_array(_player.raycast_sensor.get_observation())
43
+ return {"obs": observations}
44
+
45
+ func get_reward() -> float:
46
+ return reward
47
+
48
+ func get_action_space() -> Dictionary:
49
+ return {
50
+ "back_thruster" : {
51
+ "size": 2,
52
+ "action_type": "discrete"
53
+ },
54
+ "forward_thruster" : {
55
+ "size": 2,
56
+ "action_type": "discrete"
57
+ },
58
+ "left_thruster" : {
59
+ "size": 2,
60
+ "action_type": "discrete"
61
+ },
62
+ "right_thruster" : {
63
+ "size": 2,
64
+ "action_type": "discrete"
65
+ },
66
+ "turn_left_thruster" : {
67
+ "size": 2,
68
+ "action_type": "discrete"
69
+ },
70
+ "turn_right_thruster" : {
71
+ "size": 2,
72
+ "action_type": "discrete"
73
+ },
74
+ "up_thruster" : {
75
+ "size": 2,
76
+ "action_type": "discrete"
77
+ },
78
+ }
79
+
80
+ func _physics_process(delta):
81
+ n_steps += 1
82
+ if n_steps > reset_after:
83
+ needs_reset = true
84
+ done = true
85
+ reward = _player.episode_ended_unsuccessfully_reward / 10.0
86
+
87
+ func set_action(action) -> void:
88
+ _player.up_thruster.thruster_strength = (
89
+ action.up_thruster
90
+ ) * _player.up_thruster_max_force
91
+ _player.forward_thruster.thruster_strength = (
92
+ action.forward_thruster
93
+ ) * _player.navigation_thruster_max_force
94
+ _player.back_thruster.thruster_strength = (
95
+ action.back_thruster
96
+ ) * _player.navigation_thruster_max_force
97
+ _player.left_thruster.thruster_strength = (
98
+ action.left_thruster
99
+ ) * _player.navigation_thruster_max_force
100
+ _player.right_thruster.thruster_strength = (
101
+ action.right_thruster
102
+ ) * _player.navigation_thruster_max_force
103
+ _player.turn_left_thruster.thruster_strength = (
104
+ action.turn_left_thruster
105
+ ) * _player.navigation_thruster_max_force
106
+ _player.turn_right_thruster.thruster_strength = (
107
+ action.turn_right_thruster
108
+ ) * _player.navigation_thruster_max_force
scenes/game_scene/Terrain.gd ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @tool
2
+ extends StaticBody3D
3
+ class_name Terrain
4
+
5
+ ## Generates the terrain for the environment.
6
+
7
+ ## Training mode disables calculating normals
8
+ ## and ambient occlusion texture to speed up generation.
9
+ ## The maybe_generate_terrain() method will not generate terrain
10
+ ## every time it is called if this is set to true.
11
+ @export var training_mode: bool = true
12
+
13
+ ## Noise used for the terrain generation.
14
+ @export var noise: FastNoiseLite
15
+ @onready var _meshInstance3D = $MeshInstance3D
16
+ @onready var _collisionShape3D = $CollisionShape3D
17
+
18
+ ## The size of the terrain.
19
+ @export var size := Vector2(80.0, 80.0)
20
+
21
+ ## How many subdivisions the terrain will have.
22
+ ## Setting this too high could cause performance issues.
23
+ @export var subdivisions := Vector2i(20, 20)
24
+ @export var noise_seed := 0
25
+
26
+ ## The height of the terrain is scaled by this multiplier.
27
+ @export var height_multiplier := 10.0
28
+
29
+ ## When enabled, the terrain shape will be random every time it is generated.
30
+ ## If disabled, the terrain shape depends on the noise seed entered.
31
+ @export var use_random_seed := true
32
+
33
+ ## Radius of the landing surface which will be mostly flat to make it easier to land.
34
+ @export var landing_surface_radius := 10.0
35
+
36
+ ## How far away from the center of the terrain can the randomly selected landing position be.
37
+ @export_range(0.0, 0.8) var landing_surface_max_dist_from_center_ratio := 0.5
38
+
39
+ @export var wall_colliders: Array[CollisionShape3D]
40
+
41
+ ## Click to regenerate the terrain in editor.
42
+ @export var regenerate_terrain := false:
43
+ get:
44
+ return false
45
+ set(_value):
46
+ generate_terrain()
47
+
48
+ @export var LandingSpotMarker: MeshInstance3D
49
+ var landing_position := Vector3(0.0, 0.0, 0.0)
50
+
51
+ func _ready():
52
+ generate_terrain()
53
+
54
+ ## Will always generate terrain if not in training mode,
55
+ ## otherwise it will only sometimes generate terrain
56
+ ## to slightly increase training fps.
57
+ func maybe_generate_terrain():
58
+ if not training_mode:
59
+ generate_terrain()
60
+ else:
61
+ if randi_range(0, 3) == 0:
62
+ generate_terrain()
63
+
64
+ func generate_terrain():
65
+ #print("generating terrain")
66
+ if use_random_seed:
67
+ noise.seed = randi()
68
+ else:
69
+ noise.seed = noise_seed
70
+
71
+ # Create a temporary plane mesh
72
+ var plane = PlaneMesh.new()
73
+ plane.size = size
74
+ plane.subdivide_depth = subdivisions.y
75
+ plane.subdivide_width = subdivisions.x
76
+
77
+ # Modify the height of vertices based on the noise data
78
+ var vertices = plane.get_mesh_arrays()[Mesh.ARRAY_VERTEX]
79
+
80
+ var range_multiplier = landing_surface_max_dist_from_center_ratio / 2
81
+
82
+ var landing_center := Vector2(
83
+ randf_range(-size.x * range_multiplier, size.x * range_multiplier),
84
+ randf_range(-size.y * range_multiplier, size.y * range_multiplier)
85
+ )
86
+
87
+ landing_position = to_global(Vector3(landing_center.x, 0.0, landing_center.y))
88
+
89
+ var edge_radius = landing_surface_radius * 3
90
+
91
+ for i in range(0, vertices.size()):
92
+ var height = height_multiplier
93
+ var vertex = vertices[i]
94
+ var dist_from_center = Vector2(vertex.x, vertex.z).distance_to(landing_center)
95
+
96
+ # Flatten a part of the terrain around the landing position
97
+ if dist_from_center <= landing_surface_radius:
98
+ height = 0
99
+ elif dist_from_center <= edge_radius:
100
+ height *= (dist_from_center - landing_surface_radius) / (edge_radius - landing_surface_radius)
101
+
102
+ vertices[i].y = noise.get_noise_2d(vertex.x, vertex.z) * height
103
+
104
+ # Create a new mesh and assign the vertices
105
+ var new_mesh = ArrayMesh.new()
106
+ var arrays = plane.get_mesh_arrays()
107
+ arrays[Mesh.ARRAY_VERTEX] = vertices
108
+ new_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
109
+ # Use the new mesh as the terrain mesh
110
+ _meshInstance3D.mesh = new_mesh
111
+
112
+ # Generate the normals for the terrain mesh
113
+ if not training_mode:
114
+ var st = SurfaceTool.new()
115
+ st.create_from(_meshInstance3D.mesh, 0)
116
+ st.generate_normals()
117
+ st.commit(_meshInstance3D.mesh)
118
+
119
+ # Set the collision shape for the terrain
120
+ _collisionShape3D.shape = _meshInstance3D.mesh.create_trimesh_shape()
121
+
122
+ # Set the ambient occlusion texture for the terrain
123
+ if not training_mode:
124
+ var texture: NoiseTexture2D = NoiseTexture2D.new()
125
+ texture.noise = noise.duplicate()
126
+ texture.width = size.x
127
+ texture.height = size.y
128
+ texture.noise.offset = Vector3(-size.x / 2.0, -size.y / 2.0, 0)
129
+ texture.normalize = false
130
+ var material: StandardMaterial3D = _meshInstance3D.get_active_material(0)
131
+ material.ao_texture = texture
132
+ material.ao_light_affect = 0.7
133
+
134
+ # Update the invisible wall collider positions
135
+ for wall_collider in wall_colliders:
136
+ wall_collider.shape.size.x = size.x
137
+ wall_collider.shape.size.y = 800
138
+ wall_collider.shape.size.z = size.y
139
+
140
+ wall_colliders[0].position = Vector3(
141
+ size.x,
142
+ 100,
143
+ 0
144
+ )
145
+ wall_colliders[1].position = Vector3(
146
+ -size.x,
147
+ 100,
148
+ 0
149
+ )
150
+ wall_colliders[2].position = Vector3(
151
+ 0,
152
+ 100,
153
+ size.y
154
+ )
155
+ wall_colliders[3].position = Vector3(
156
+ 0,
157
+ 100,
158
+ -size.y
159
+ )
160
+ wall_colliders[4].position = Vector3(
161
+ 0,
162
+ 800,
163
+ 0
164
+ )
165
+
166
+ LandingSpotMarker.global_position = landing_position + Vector3.DOWN * 0.05
167
+ var LandingSpotMarkerMesh = LandingSpotMarker.mesh as SphereMesh
168
+ LandingSpotMarkerMesh.radius = landing_surface_radius
169
+ LandingSpotMarkerMesh.height = landing_surface_radius
scenes/game_scene/Thruster.gd ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends MeshInstance3D
2
+ class_name Thruster
3
+
4
+ ## Lander thruster. This class keeps track of current activation strength
5
+ ## and handles the particle effects.
6
+
7
+ var thruster_strength: float
8
+ @onready var _particles: GPUParticles3D = $GPUParticles3D
9
+ var _material: ParticleProcessMaterial
10
+
11
+ func _ready():
12
+ _material = _particles.process_material
13
+
14
+ func _physics_process(delta):
15
+ if thruster_strength > 0.01:
16
+ if not _particles.emitting:
17
+ _particles.emitting = true
18
+ _material.initial_velocity_max = 0.01 + thruster_strength / 300.0
19
+ _material.initial_velocity_min = _material.initial_velocity_max
20
+ else:
21
+ if _particles.emitting:
22
+ _particles.emitting = false
scenes/game_scene/game_scene.tscn ADDED
The diff for this file is too large to render. See raw diff
 
scenes/testing_scene/manual_test_scene.tscn ADDED
The diff for this file is too large to render. See raw diff
 
scenes/testing_scene/testing_scene.tscn ADDED
The diff for this file is too large to render. See raw diff
 
scenes/training_scene/SyncAddControlModeSelection.gd ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ extends "res://addons/godot_rl_agents/sync.gd"
2
+
3
+ ## Adds the control mode selection from: https://github.com/edbeeching/godot_rl_agents_plugin/pull/19
4
+ enum ControlModes {HUMAN, TRAINING, ONNX_INFERENCE}
5
+ @export var control_mode: ControlModes = ControlModes.TRAINING
6
+
7
+ func _initialize():
8
+ _get_agents()
9
+ _obs_space = agents[0].get_obs_space()
10
+ _action_space = agents[0].get_action_space()
11
+ args = _get_args()
12
+ Engine.physics_ticks_per_second = _get_speedup() * 60
13
+ Engine.time_scale = _get_speedup() * 1.0
14
+ prints("physics ticks", Engine.physics_ticks_per_second, Engine.time_scale, _get_speedup(), speed_up)
15
+
16
+ _set_heuristic("human")
17
+ match control_mode:
18
+ ControlModes.TRAINING:
19
+ connected = connect_to_server()
20
+ if connected:
21
+ _set_heuristic("model")
22
+ _handshake()
23
+ _send_env_info()
24
+ else:
25
+ push_warning("Couldn't connect to Python server, using human controls instead. ",
26
+ "Did you start the training server using e.g. `gdrl` from the console?")
27
+ ControlModes.ONNX_INFERENCE:
28
+ assert(FileAccess.file_exists(onnx_model_path), "Onnx Model Path set on Sync node does not exist: %s" % onnx_model_path)
29
+ onnx_model = ONNXModel.new(onnx_model_path, 1)
30
+ _set_heuristic("model")
31
+ ControlModes.HUMAN:
32
+ _reset_all_agents()
33
+
34
+ _set_seed()
35
+ _set_action_repeat()
36
+ initialized = true
scenes/training_scene/training_scene.tscn ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gd_scene load_steps=3 format=3 uid="uid://dwwqctrnbhrru"]
2
+
3
+ [ext_resource type="PackedScene" uid="uid://bkebr724kehsw" path="res://scenes/game_scene/game_scene.tscn" id="1_7pikd"]
4
+ [ext_resource type="Script" path="res://scenes/training_scene/SyncAddControlModeSelection.gd" id="2_st3rd"]
5
+
6
+ [node name="TrainingScene" type="Node3D"]
7
+
8
+ [node name="GameScene" parent="." instance=ExtResource("1_7pikd")]
9
+
10
+ [node name="GameScene2" parent="." instance=ExtResource("1_7pikd")]
11
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3093, 0, 0)
12
+
13
+ [node name="GameScene3" parent="." instance=ExtResource("1_7pikd")]
14
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -3053)
15
+
16
+ [node name="GameScene4" parent="." instance=ExtResource("1_7pikd")]
17
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3093, 0, -3053)
18
+
19
+ [node name="GameScene5" parent="." instance=ExtResource("1_7pikd")]
20
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3013)
21
+
22
+ [node name="GameScene6" parent="." instance=ExtResource("1_7pikd")]
23
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3093, 0, 3013)
24
+
25
+ [node name="GameScene7" parent="." instance=ExtResource("1_7pikd")]
26
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6033, 0, 0)
27
+
28
+ [node name="GameScene8" parent="." instance=ExtResource("1_7pikd")]
29
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2940, 0, 0)
30
+
31
+ [node name="GameScene9" parent="." instance=ExtResource("1_7pikd")]
32
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6033, 0, -3053)
33
+
34
+ [node name="GameScene10" parent="." instance=ExtResource("1_7pikd")]
35
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2940, 0, -3053)
36
+
37
+ [node name="GameScene11" parent="." instance=ExtResource("1_7pikd")]
38
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6033, 0, 3013)
39
+
40
+ [node name="GameScene12" parent="." instance=ExtResource("1_7pikd")]
41
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2940, 0, 3013)
42
+
43
+ [node name="GameScene13" parent="." instance=ExtResource("1_7pikd")]
44
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12116, 0, -3053)
45
+
46
+ [node name="GameScene14" parent="." instance=ExtResource("1_7pikd")]
47
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9023, 0, -3053)
48
+
49
+ [node name="GameScene15" parent="." instance=ExtResource("1_7pikd")]
50
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12116, 0, 3013)
51
+
52
+ [node name="GameScene16" parent="." instance=ExtResource("1_7pikd")]
53
+ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9023, 0, 3013)
54
+
55
+ [node name="Sync" type="Node" parent="."]
56
+ script = ExtResource("2_st3rd")
57
+ speed_up = 10
58
+
59
+ [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
60
+ transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 0, 0)
61
+ sky_mode = 1