From 0fd3098f143c3b5b457ac83b40ca433a26439ba2 Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:12:59 +0000 Subject: [PATCH] feat(*): Split out vehicle object --- Game/objects/vehicle.tscn | 21 +++++++++++ Game/scenes/match.tscn | 70 ++++++++++++++++++----------------- Game/scripts/MatchCamera3D.gd | 2 +- Game/scripts/Vehicle.gd | 1 + 4 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 Game/objects/vehicle.tscn diff --git a/Game/objects/vehicle.tscn b/Game/objects/vehicle.tscn new file mode 100644 index 0000000..8d0eda9 --- /dev/null +++ b/Game/objects/vehicle.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=4 format=3 uid="uid://dnra1buk328d"] + +[ext_resource type="Script" path="res://scripts/Vehicle.gd" id="1_5snef"] + +[sub_resource type="BoxShape3D" id="BoxShape3D_0otfk"] +size = Vector3(0.5, 0.5, 1) + +[sub_resource type="BoxMesh" id="BoxMesh_uwum7"] +size = Vector3(0.5, 0.5, 1) + +[node name="Vehicle" type="RigidBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 0.5, 2) +mass = 10.0 +gravity_scale = 10.0 +script = ExtResource("1_5snef") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("BoxShape3D_0otfk") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +mesh = SubResource("BoxMesh_uwum7") diff --git a/Game/scenes/match.tscn b/Game/scenes/match.tscn index 9809e3f..5d8188a 100644 --- a/Game/scenes/match.tscn +++ b/Game/scenes/match.tscn @@ -1,41 +1,48 @@ [gd_scene load_steps=9 format=3 uid="uid://djlfte5nx8sel"] -[ext_resource type="Script" path="res://scripts/Vehicle.gd" id="1_xcj6u"] +[ext_resource type="PackedScene" uid="uid://dnra1buk328d" path="res://objects/vehicle.tscn" id="2_2d4ji"] [ext_resource type="Script" path="res://scripts/MatchCamera3D.gd" id="2_n3g6s"] +[ext_resource type="PackedScene" uid="uid://cofdcxo5170rs" path="res://objects/goal.tscn" id="3_xk008"] +[ext_resource type="Script" path="res://scripts/goal2.gd" id="4_ukkeh"] -[sub_resource type="BoxShape3D" id="BoxShape3D_xf0b8"] -size = Vector3(1, 0.5, 0.5) +[sub_resource type="BoxMesh" id="BoxMesh_xotuo"] +size = Vector3(10, 0.5, 10) -[sub_resource type="BoxMesh" id="BoxMesh_ox3jn"] -size = Vector3(1, 0.5, 0.5) +[sub_resource type="BoxShape3D" id="BoxShape3D_133xi"] +size = Vector3(10, 0.5, 10) [sub_resource type="SphereShape3D" id="SphereShape3D_c5p07"] [sub_resource type="SphereMesh" id="SphereMesh_uxjj0"] -[sub_resource type="BoxShape3D" id="BoxShape3D_gyxf6"] -size = Vector3(50, 0.1, 50) - -[sub_resource type="BoxMesh" id="BoxMesh_vk12m"] -size = Vector3(50, 0.1, 50) - [node name="MatchNode3D" type="Node3D"] -[node name="Vehicle" type="RigidBody3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.97288, 1.24949, 0.0115612) -mass = 10.0 -gravity_scale = 10.0 -script = ExtResource("1_xcj6u") +[node name="MatchCamera3D" type="Camera3D" parent="." node_paths=PackedStringArray("vehicle", "ball")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 1.33585, 3.3972) +current = true +fov = 114.877 +script = ExtResource("2_n3g6s") +vehicle = NodePath("../Players/Player1") +ball = NodePath("../Ball") -[node name="CollisionShape3D" type="CollisionShape3D" parent="Vehicle"] -shape = SubResource("BoxShape3D_xf0b8") +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(0.908048, -0.417905, 0.0283578, 0.372456, 0.836559, 0.401802, -0.191638, -0.354294, 0.915287, 0, 3.7388, 0.115907) +shadow_enabled = true -[node name="MeshInstance3D" type="MeshInstance3D" parent="Vehicle"] -mesh = SubResource("BoxMesh_ox3jn") +[node name="Floor" type="StaticBody3D" parent="."] +metadata/_edit_group_ = true + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Floor"] +mesh = SubResource("BoxMesh_xotuo") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor"] +shape = SubResource("BoxShape3D_133xi") [node name="Ball" type="RigidBody3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.00382, 1.26061, 0) -mass = 10.0 +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 2, 2.08165e-12) +mass = 100.0 +inertia = Vector3(100, 100, 100) +metadata/_edit_group_ = true [node name="CollisionShape3D" type="CollisionShape3D" parent="Ball"] shape = SubResource("SphereShape3D_c5p07") @@ -43,18 +50,13 @@ shape = SubResource("SphereShape3D_c5p07") [node name="MeshInstance3D" type="MeshInstance3D" parent="Ball"] mesh = SubResource("SphereMesh_uxjj0") -[node name="MatchCamera3D" type="Camera3D" parent="." node_paths=PackedStringArray("vehicle", "ball")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 2.08165e-12, 2.08165e-12) -current = true -fov = 114.877 -script = ExtResource("2_n3g6s") -vehicle = NodePath("../Vehicle") -ball = NodePath("../Ball") +[node name="Players" type="Node3D" parent="."] -[node name="Floor" type="StaticBody3D" parent="."] +[node name="Player1" parent="Players" instance=ExtResource("2_2d4ji")] -[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor"] -shape = SubResource("BoxShape3D_gyxf6") +[node name="Goals" type="Node3D" parent="."] -[node name="MeshInstance3D" type="MeshInstance3D" parent="Floor"] -mesh = SubResource("BoxMesh_vk12m") +[node name="Goal2" parent="Goals" node_paths=PackedStringArray("ball") instance=ExtResource("3_xk008")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 1, -5) +script = ExtResource("4_ukkeh") +ball = NodePath("../../Ball") diff --git a/Game/scripts/MatchCamera3D.gd b/Game/scripts/MatchCamera3D.gd index ba93e55..ef7f1ec 100644 --- a/Game/scripts/MatchCamera3D.gd +++ b/Game/scripts/MatchCamera3D.gd @@ -7,7 +7,7 @@ func _physics_process(delta): if vehicle and ball: # Adjust the offset based on your scene scale # Increasing Y component to raise the camera higher above the vehicle - var offset = Vector3(0, 10, 10) # Adjust Y to change height + var offset = Vector3(0, 2, -2) # Adjust Y to change height # Position the camera behind and above the vehicle var behind_vehicle = vehicle.global_transform.origin - vehicle.global_transform.basis.z * offset.z diff --git a/Game/scripts/Vehicle.gd b/Game/scripts/Vehicle.gd index 33fd102..ee34692 100644 --- a/Game/scripts/Vehicle.gd +++ b/Game/scripts/Vehicle.gd @@ -3,6 +3,7 @@ extends RigidBody3D var speed = 10.0 # Adjust the speed as necessary func _integrate_forces(state): + # TODO - change these so they are relative to the vehicle, not the world var input_vector = Vector3.ZERO if Input.is_action_pressed("move_forward"): input_vector.z -= 1