Greetings!<br /><br />I came across Godot a few days ago so I'm fairly new. I have coded before but that's some time ago. I thought the best way to learn it would be by ignoring most of the editor for now and do everything via scripts first. Most questions got easily solved using the documentation and google but I couldn't find answers to all of them.<br /><br />I created a blank project, added a "Spatial" node called 'Spatial' and attached a script to it. <br />
# Main.gd<br /><br />extends Spatial<br /><br />var cam;<br />var cube;<br />var light;<br />var ground;<br />var wall;<br />var wall_mesh;<br />var wall_coll;<br /><br />var player;<br />var player_mesh;<br />var player_coll;<br /><br />func
ready():<br /> self.set_process(true);<br /> self.set_fixed_process(true);<br /> self.set_process_input(true);<br /><br /> player = KinematicBody.new();<br /> add_child(player);<br /> <br /> player_mesh = TestCube.new();<br /> player.add_child(player_mesh);<br /> player_mesh.set_scale(Vector3(.3, .5, .3));<br /> player_mesh.set_translation(player.get_translation() + Vector3(0, .5, 0));<br /> <br /> player_coll = CollisionShape.new();<br /> player_mesh.add_child(player_coll);<br /> player_coll.set_shape(player_mesh);<br /> <br /> wall = StaticBody.new();<br /> add_child(wall);<br /> <br /> wall_mesh = TestCube.new();<br /> wall_mesh.set_scale(Vector3(.2, 2, 6));<br /> wall_mesh.set_translation(Vector3(5, 0, 0));<br /> wall.add_child(wall_mesh);<br /> <br /> wall_coll = CollisionShape.new();<br /> wall_mesh.add_child(wall_coll);<br /> wall_coll.set_shape(wall);<br /> <br /> cam = Camera.new();<br /> add_child(cam);<br /> cam.set_rotation(Vector3(-1.57, 0, 0));<br /> <br /> cube = TestCube.new();<br /> add_child(cube);<br /> cube.set_translation(Vector3(3.8, 1, 0));<br /> cube.set_scale(Vector3(.5, .5, .5));<br /> <br /> ground = TestCube.new();<br /> add_child(ground);<br /> ground.set_scale(Vector3(20, .1, 20));<br /> ground.set_translation(Vector3(0, -.09, 0));<br /> <br /> light = DirectionalLight.new();<br /> add_child(light);<br /> light.set_rotation_deg(Vector3(230, -30, 0));<br /> light.set_project_shadows(true);<br /> light.set_parameter(light.PARAM_ENERGY, 1.3)<br /> light.set_parameter(light.PARAM_SHADOW_DARKENING, .2);<br /> light.set_shadow_mode(light.SHADOW_PARALLEL_4_SPLITS);<br /> light.set_enabled(true);<br /><br /><br />#====================================================================<br /><br />var rota = 0;<br />var w;<br />var
s;<br />var a;<br />var
d;<br />var sprint;<br /><br />var dir = 0;<br />var x;<br />const MOVESPEED = 5;<br />const ROTASPEED = 3;<br />const SPRINTADD = 2;<br /><br /><br />func
input(ev):<br /> if (ev.is_action_released(&quot;ui_accept&quot;)):<br /> x = get_node(&quot;CFunctions&quot;).cNew(player.get_translation());<br /> print(&quot;PING!&quot;);<br /> add_child(x);<br /> <br /> <a rel="nofollow" target="blank">#
w</a> = (ev.is_action_pressed(&quot;up&quot;));<br /> <a rel="nofollow" target="blank">#
s</a> = (ev.is_action_pressed(&quot;down&quot;));<br /> <a rel="nofollow" target="blank">#
a</a> = (ev.is_action_pressed(&quot;left&quot;));<br /> <a rel="nofollow" target="blank">#
d</a> = (ev.is_action_pressed(&quot;right&quot;));<br /><br />func process(delta):<br /> <br /> # Input<br />
w = Input.is_key_pressed(KEY_W);<br /> s = Input.is_key_pressed(KEY_S);<br />
a = Input.is_key_pressed(KEY_A);<br /> d = Input.is_key_pressed(KEY_D);<br /> <br /> # Quit<br /> if (Input.is_key_pressed(KEY_ESCAPE)):<br /> get_node(&quot;CFunctions&quot;).cGameQuit();<br /> <br /> # Rotate cube<br /> rota += 2
delta;<br /> cube.set_rotation(Vector3(rota, .5 -rota, rota));<br /><br /><br />#====================================================================<br /><br />var move;<br />var tar_x;<br />var tar_z;<br /><br />func
fixed_process(delta):<br /> #MOVEMENT<br /> if (w or
s or a or
d):<br /> move = w -
s;<br /> <br /> tar_x = get_node(&quot;CFunctions&quot;).cLengthDirX(move MOVESPEED, dir);<br /> tar_z = get_node(&quot;CFunctions&quot;).cLenghtDirZ(move MOVESPEED, dir);<br /> player.move(Vector3(tar_x delta, 0, tar_z delta));<br /> <br /> if (a): dir += (ROTASPEED&nbsp; + (SPRINTADD / 2));<br /> if (
d): dir -= (ROTASPEED + (SPRINTADD / 2));<br /> print(dir);<br /> player.set_rotation(Vector3(0, deg2rad(dir), 0));<br /> <br /> cam.set_translation(player.get_translation() + Vector3(0, 10, 0));
<br /><br />Then I added another "Spatial" node called 'CFunctions' as a child to the first Spatial Node and attached this script to it containing:<br /><br />
extends Spatial<br /><br />func cGameQuit():<br /> get_tree().quit();<br /><br />func cNew(trns):<br /> var c = TestCube.new();<br /> c.set_translation(trns);<br /> c.set_scale(Vector3(2, 2, 2));<br /> return c;<br /><br />func cLengthDirX(var len, var dir):<br /> return (cos(-dir (PI / 180)) len);<br /><br />func cLenghtDirZ(var len, var dir):<br /> return (sin(-dir (PI / 180)) len);
<br /><br />Which is basically just a container for functions, which brings me to my first question: <br />1 - Is there any better way to "#include" simple library code from another *.gd file (with code completion)?<br />2 - I couldn't get 'func _input()' to work properly, so I hardcoded the controls in 'func process()'. input() does receive an Input, but only one key at a time and just for a few seconds.<br />3 - How do I get the 'player' to collide with 'wall' using the built-in 3D collision system? I couldn't figure out how to set it up.<br /><br />Also, I much appreciate any tips on 'good coding practice' <img alt="" height="20">