From: Clifton Palmer Date: Sun, 14 Nov 2021 18:03:31 +0000 (-0600) Subject: Initial flight mechanics X-Git-Url: http://git.purplebirdman.com/star-foxy.git/commitdiff_plain/aa5570c71a74c44b300ec57dab7d4a4c07b98f72?hp=2e08d557a1d708ffd46274822eb003766317163e Initial flight mechanics --- diff --git a/main.tscn b/main.tscn new file mode 100644 index 0000000..9ab4da0 --- /dev/null +++ b/main.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://player/player.tscn" type="PackedScene" id=1] + +[node name="world" type="Spatial"] + +[node name="boxes" type="Spatial" parent="."] + +[node name="CSGBox" type="CSGBox" parent="boxes"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 8 ) + +[node name="CSGBox2" type="CSGBox" parent="boxes"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 10.6742, 0, 0 ) + +[node name="CSGBox3" type="CSGBox" parent="boxes"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -11.353, 0, 0 ) + +[node name="arwing" parent="." instance=ExtResource( 1 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0547695, 0, 35.9027 ) diff --git a/player/player.gd b/player/player.gd new file mode 100644 index 0000000..0dbb6d9 --- /dev/null +++ b/player/player.gd @@ -0,0 +1,36 @@ +extends KinematicBody + +const SPEED = 20 + +var velocity = Vector3() + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func get_player_input(delta): + var cam_vec_lateral = $Camera.transform.basis.x + var cam_vec_vertical = $Camera.transform.basis.y + + + if Input.is_action_pressed("player_left"): + velocity += SPEED * cam_vec_lateral * delta + elif Input.is_action_pressed("player_right"): + velocity += SPEED * -cam_vec_lateral * delta + + if Input.is_action_pressed("player_up"): + velocity += SPEED * cam_vec_vertical * delta + elif Input.is_action_pressed("player_down"): + velocity += SPEED * -cam_vec_vertical * delta + + +func _process(delta): + # move foward according to the camera's POV + var cam_vec_forward = $Camera.transform.basis.z + velocity += SPEED * -cam_vec_forward * delta + + # get velocity changes player asks for + get_player_input(delta) + +func _physics_process(_delta): + velocity = move_and_slide(velocity, Vector3.UP) diff --git a/player/player.tscn b/player/player.tscn index 60631c2..7ef0343 100644 --- a/player/player.tscn +++ b/player/player.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://model/arwing_wings.material" type="Material" id=1] [ext_resource path="res://model/arwing_body.material" type="Material" id=2] +[ext_resource path="res://player/player.gd" type="Script" id=3] [sub_resource type="SpatialMaterial" id=1] vertex_color_use_as_albedo = true @@ -52,22 +53,29 @@ surfaces/0 = { } [sub_resource type="BoxShape" id=5] -extents = Vector3( 3.72203, 0.878147, 2.99408 ) +extents = Vector3( 3.72203, 0.878147, 3.13957 ) [node name="arwing" type="KinematicBody"] +script = ExtResource( 3 ) -[node name="body" type="MeshInstance" parent="."] +[node name="mesh" type="Spatial" parent="."] +transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0 ) + +[node name="body" type="MeshInstance" parent="mesh"] mesh = SubResource( 2 ) material/0 = null -[node name="thrust" type="MeshInstance" parent="."] +[node name="thrust" type="MeshInstance" parent="mesh"] mesh = SubResource( 3 ) material/0 = null -[node name="wings" type="MeshInstance" parent="."] +[node name="wings" type="MeshInstance" parent="mesh"] mesh = SubResource( 4 ) material/0 = null [node name="CollisionShape" type="CollisionShape" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.371765, 0.63321 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.371765, -0.470031 ) shape = SubResource( 5 ) + +[node name="Camera" type="Camera" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 13.3084 ) diff --git a/project.godot b/project.godot index 9f02eae..9fb6ae2 100644 --- a/project.godot +++ b/project.godot @@ -11,8 +11,42 @@ config_version=4 [application] config/name="star-foxy" +run/main_scene="res://main.tscn" config/icon="res://icon.png" +[input] + +player_up={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) + ] +} +player_down={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) + ] +} +player_left={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) + ] +} +player_right={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) + ] +} +player_boost={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null) + ] +} +player_fire={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":7,"pressure":0.0,"pressed":false,"script":null) + ] +} + [physics] common/enable_pause_aware_picking=true