feat(*): Split out vehicle object

This commit is contained in:
Josh Creek
2024-02-23 18:12:59 +00:00
parent 5d518cbcfb
commit 0fd3098f14
4 changed files with 59 additions and 35 deletions
+21
View File
@@ -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")
+36 -34
View File
@@ -1,41 +1,48 @@
[gd_scene load_steps=9 format=3 uid="uid://djlfte5nx8sel"] [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="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"] [sub_resource type="BoxMesh" id="BoxMesh_xotuo"]
size = Vector3(1, 0.5, 0.5) size = Vector3(10, 0.5, 10)
[sub_resource type="BoxMesh" id="BoxMesh_ox3jn"] [sub_resource type="BoxShape3D" id="BoxShape3D_133xi"]
size = Vector3(1, 0.5, 0.5) size = Vector3(10, 0.5, 10)
[sub_resource type="SphereShape3D" id="SphereShape3D_c5p07"] [sub_resource type="SphereShape3D" id="SphereShape3D_c5p07"]
[sub_resource type="SphereMesh" id="SphereMesh_uxjj0"] [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="MatchNode3D" type="Node3D"]
[node name="Vehicle" type="RigidBody3D" parent="."] [node name="MatchCamera3D" type="Camera3D" parent="." node_paths=PackedStringArray("vehicle", "ball")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.97288, 1.24949, 0.0115612) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 1.33585, 3.3972)
mass = 10.0 current = true
gravity_scale = 10.0 fov = 114.877
script = ExtResource("1_xcj6u") script = ExtResource("2_n3g6s")
vehicle = NodePath("../Players/Player1")
ball = NodePath("../Ball")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Vehicle"] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
shape = SubResource("BoxShape3D_xf0b8") 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"] [node name="Floor" type="StaticBody3D" parent="."]
mesh = SubResource("BoxMesh_ox3jn") 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="."] [node name="Ball" type="RigidBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.00382, 1.26061, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 2, 2.08165e-12)
mass = 10.0 mass = 100.0
inertia = Vector3(100, 100, 100)
metadata/_edit_group_ = true
[node name="CollisionShape3D" type="CollisionShape3D" parent="Ball"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Ball"]
shape = SubResource("SphereShape3D_c5p07") shape = SubResource("SphereShape3D_c5p07")
@@ -43,18 +50,13 @@ shape = SubResource("SphereShape3D_c5p07")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Ball"] [node name="MeshInstance3D" type="MeshInstance3D" parent="Ball"]
mesh = SubResource("SphereMesh_uxjj0") mesh = SubResource("SphereMesh_uxjj0")
[node name="MatchCamera3D" type="Camera3D" parent="." node_paths=PackedStringArray("vehicle", "ball")] [node name="Players" type="Node3D" parent="."]
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="Floor" type="StaticBody3D" parent="."] [node name="Player1" parent="Players" instance=ExtResource("2_2d4ji")]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor"] [node name="Goals" type="Node3D" parent="."]
shape = SubResource("BoxShape3D_gyxf6")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floor"] [node name="Goal2" parent="Goals" node_paths=PackedStringArray("ball") instance=ExtResource("3_xk008")]
mesh = SubResource("BoxMesh_vk12m") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, 1, -5)
script = ExtResource("4_ukkeh")
ball = NodePath("../../Ball")
+1 -1
View File
@@ -7,7 +7,7 @@ func _physics_process(delta):
if vehicle and ball: if vehicle and ball:
# Adjust the offset based on your scene scale # Adjust the offset based on your scene scale
# Increasing Y component to raise the camera higher above the vehicle # 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 # Position the camera behind and above the vehicle
var behind_vehicle = vehicle.global_transform.origin - vehicle.global_transform.basis.z * offset.z var behind_vehicle = vehicle.global_transform.origin - vehicle.global_transform.basis.z * offset.z
+1
View File
@@ -3,6 +3,7 @@ extends RigidBody3D
var speed = 10.0 # Adjust the speed as necessary var speed = 10.0 # Adjust the speed as necessary
func _integrate_forces(state): func _integrate_forces(state):
# TODO - change these so they are relative to the vehicle, not the world
var input_vector = Vector3.ZERO var input_vector = Vector3.ZERO
if Input.is_action_pressed("move_forward"): if Input.is_action_pressed("move_forward"):
input_vector.z -= 1 input_vector.z -= 1