This commit is contained in:
Crizomb 2025-08-02 23:51:48 +02:00
parent ad95711535
commit 2e310f4053
25 changed files with 852 additions and 74 deletions

View file

@ -1,6 +1,8 @@
extends RigidBody3D
class_name Car
@export var road_path : RoadPath
@export var forward_force: float = 100.0
@export var backward_force: float = 50.0
@export var steer_speed: float = 2.0
@ -9,10 +11,10 @@ class_name Car
@export var lateral_velocity_start_drift_threshold: float = 10.0
@export var lateral_velocity_total_drift_threshold: float = 15.0
@onready var forward_left: RayCast3D = $Raycasts/ForwardLeft
@onready var forward_right: RayCast3D = $Raycasts/ForwardRight
@onready var backward_right: RayCast3D = $Raycasts/BackwardRight
@onready var backward_left: RayCast3D = $Raycasts/BackwardLeft
@onready var forward_left: RayCast3D = $ForwardLeft
@onready var forward_right: RayCast3D = $ForwardRight
@onready var backward_right: RayCast3D = $BackwardRight
@onready var backward_left: RayCast3D = $BackwardLeft
@onready var forward_left_respawn: RayCast3D = $RaycastsRespawn/ForwardLeftRespawn
@onready var forward_right_respawn: RayCast3D = $RaycastsRespawn/ForwardRightRespawn
@ -31,10 +33,13 @@ var respawn_pos : Vector3
var thread: Thread = Thread.new()
var steer_input = 0.0
var cheat := false
var air_time := 0.0
func custom_gravity() -> Vector3:
var attractor = road_path.to_global(road_path.curve.get_closest_point(road_path.to_local(position)))
return (attractor - position).normalized()
func return_to_road():
position = respawn_pos + 3*Vector3.UP
rotation.z = 0
@ -58,10 +63,13 @@ func _physics_process(delta: float) -> void:
var is_all_wheel_on_floor := backward_left_respawn.is_colliding() && backward_right_respawn.is_colliding() && forward_left_respawn.is_colliding() && forward_right_respawn.is_colliding()
var is_flat : bool = transform.basis.y.dot(Vector3.UP) > 0.9
# Doing custom gravity like a chad
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY_VECTOR, custom_gravity())
if is_all_wheel_on_floor && is_flat:
respawn_pos = position
if !is_on_floor && !cheat:
if !is_on_floor:
#$DriftParticles.emitting = false
#$DriftParticles2.emitting = false
#AudioServer.set_bus_volume_db(5, -80)
@ -70,10 +78,6 @@ func _physics_process(delta: float) -> void:
return_to_road()
return
air_time = 0.0
if cheat && Input.is_key_pressed(KEY_SPACE):
linear_velocity.y += 20*delta
if cheat:
forward_force = 500
# Movement
if move_input > 0.0:
@ -117,5 +121,3 @@ func _physics_process(delta: float) -> void:
apply_central_force(lateral_friction_force)

View file

@ -1,38 +1,48 @@
[gd_scene load_steps=4 format=3 uid="uid://dgs0fqojgcmu3"]
[gd_scene load_steps=6 format=3 uid="uid://dgs0fqojgcmu3"]
[ext_resource type="Script" uid="uid://ctjy0e806j0vk" path="res://entities/car/car.gd" id="1_nh45c"]
[ext_resource type="PackedScene" uid="uid://drrl25ujbosbr" path="res://entities/car/tron_moto_lowpoly/scene.gltf" id="2_1ang0"]
[sub_resource type="BoxMesh" id="BoxMesh_kkl2f"]
size = Vector3(1, 1, 2)
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_1ang0"]
friction = 0.5
[sub_resource type="BoxShape3D" id="BoxShape3D_76tdi"]
size = Vector3(1, 1, 2)
size = Vector3(1, 1, 2.2)
[sub_resource type="CylinderShape3D" id="CylinderShape3D_yotxw"]
height = 1.1
[node name="Car" type="RigidBody3D"]
mass = 10.0
physics_material_override = SubResource("PhysicsMaterial_1ang0")
script = ExtResource("1_nh45c")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("BoxMesh_kkl2f")
[node name="ForwardLeft" type="RayCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 0.435121, -1)
[node name="ForwardRight" type="RayCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.435121, -1)
[node name="BackwardRight" type="RayCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.435121, 1)
[node name="BackwardLeft" type="RayCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 0.435121, 1)
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.00250244)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.1)
shape = SubResource("BoxShape3D_76tdi")
[node name="Raycasts" type="Node3D" parent="."]
[node name="CollisionShape3D2" type="CollisionShape3D" parent="."]
transform = Transform3D(-4.37114e-08, 1, -4.37114e-08, 0, -4.37114e-08, -1, -1, -4.37114e-08, 1.91069e-15, 0, 0, 1)
shape = SubResource("CylinderShape3D_yotxw")
[node name="ForwardLeft" type="RayCast3D" parent="Raycasts"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 0, -1)
[node name="ForwardRight" type="RayCast3D" parent="Raycasts"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, -1)
[node name="BackwardRight" type="RayCast3D" parent="Raycasts"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, 1)
[node name="BackwardLeft" type="RayCast3D" parent="Raycasts"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 0, 1)
[node name="CollisionShape3D3" type="CollisionShape3D" parent="."]
transform = Transform3D(-4.37114e-08, 1, -4.37114e-08, 0, -4.37114e-08, -1, -1, -4.37114e-08, 1.91069e-15, 0, 0, -1.2)
shape = SubResource("CylinderShape3D_yotxw")
[node name="RaycastsRespawn" type="Node3D" parent="."]
transform = Transform3D(2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0)
[node name="ForwardLeftRespawn" type="RayCast3D" parent="RaycastsRespawn"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 0, -1)
@ -45,3 +55,11 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, 1)
[node name="BackwardLeftRespawn" type="RayCast3D" parent="RaycastsRespawn"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 0, 1)
[node name="Sketchfab_Scene" parent="." instance=ExtResource("2_1ang0")]
transform = Transform3D(-0.35, 0, -3.0598e-08, 0, 0.35, 0, 3.0598e-08, 0, -0.35, 0.0317484, -0.52664, 0)
[node name="CameraFollowPoint" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.31962, -2.93594)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View file

@ -0,0 +1,11 @@
Model Information:
* title: TRON MOTO LOWPOLY
* source: https://sketchfab.com/3d-models/tron-moto-lowpoly-440eb1d0f37e475ca7eda15517f66552
* author: gedebotax1984 (https://sketchfab.com/gedebotax1984)
Model License:
* license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
* requirements: Author must be credited. Commercial use is allowed.
If you use this 3D model in your project be sure to copy paste this credit wherever you share it:
This work is based on "TRON MOTO LOWPOLY" (https://sketchfab.com/3d-models/tron-moto-lowpoly-440eb1d0f37e475ca7eda15517f66552) by gedebotax1984 (https://sketchfab.com/gedebotax1984) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)

Binary file not shown.

View file

@ -0,0 +1,488 @@
{
"accessors": [
{
"bufferView": 2,
"componentType": 5126,
"count": 5771,
"max": [
1.418189525604248,
-3.2901666164398193,
8.152215957641602
],
"min": [
-2.154029607772827,
-5.40167760848999,
-1.4549527168273926
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 69252,
"componentType": 5126,
"count": 5771,
"max": [
1.0,
1.0,
1.0
],
"min": [
-1.0,
-1.0,
-1.0
],
"type": "VEC3"
},
{
"bufferView": 1,
"componentType": 5126,
"count": 5771,
"max": [
0.0,
0.0
],
"min": [
0.0,
0.0
],
"type": "VEC2"
},
{
"bufferView": 0,
"componentType": 5125,
"count": 13137,
"type": "SCALAR"
},
{
"bufferView": 2,
"byteOffset": 138504,
"componentType": 5126,
"count": 3506,
"max": [
44.090858459472656,
9.652633666992188,
34.13569641113281
],
"min": [
-2.5885181427001953,
-40.4989013671875,
-117.7420883178711
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 180576,
"componentType": 5126,
"count": 3506,
"max": [
0.9996709823608398,
1.0,
0.9999953508377075
],
"min": [
-0.9996709227561951,
-1.0,
-0.9999963045120239
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 46168,
"componentType": 5126,
"count": 3506,
"max": [
1.0,
1.0
],
"min": [
0.0,
0.0
],
"type": "VEC2"
},
{
"bufferView": 0,
"byteOffset": 52548,
"componentType": 5125,
"count": 5856,
"type": "SCALAR"
},
{
"bufferView": 2,
"byteOffset": 222648,
"componentType": 5126,
"count": 6878,
"max": [
3.3031864166259766,
2.111264705657959,
4.73450231552124
],
"min": [
0.1486961841583252,
-0.15285027027130127,
-4.455859184265137
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 305184,
"componentType": 5126,
"count": 6878,
"max": [
0.9998899698257446,
1.0,
0.999742329120636
],
"min": [
-0.999989926815033,
-1.0,
-0.9999964237213135
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 74216,
"componentType": 5126,
"count": 6878,
"max": [
1.0,
1.0
],
"min": [
0.0,
0.0
],
"type": "VEC2"
},
{
"bufferView": 0,
"byteOffset": 75972,
"componentType": 5125,
"count": 11328,
"type": "SCALAR"
}
],
"asset": {
"extras": {
"author": "gedebotax1984 (https://sketchfab.com/gedebotax1984)",
"license": "CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)",
"source": "https://sketchfab.com/3d-models/tron-moto-lowpoly-440eb1d0f37e475ca7eda15517f66552",
"title": "TRON MOTO LOWPOLY"
},
"generator": "Sketchfab-15.30.0",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 121284,
"name": "floatBufferViews",
"target": 34963
},
{
"buffer": 0,
"byteLength": 129240,
"byteOffset": 121284,
"byteStride": 8,
"name": "floatBufferViews",
"target": 34962
},
{
"buffer": 0,
"byteLength": 387720,
"byteOffset": 250524,
"byteStride": 12,
"name": "floatBufferViews",
"target": 34962
}
],
"buffers": [
{
"byteLength": 638244,
"uri": "scene.bin"
}
],
"extensionsUsed": [
"KHR_materials_clearcoat",
"KHR_materials_specular"
],
"materials": [
{
"doubleSided": true,
"extensions": {
"KHR_materials_clearcoat": {
"clearcoatFactor": 1.0,
"clearcoatRoughnessFactor": 0.04
},
"KHR_materials_specular": {
"specularColorFactor": [
1.0,
1.0,
1.0
],
"specularFactor": 0.9798125099047921
}
},
"name": "Material",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.001712375681525524,
9.849948610545045e-05,
9.849948610545045e-05,
1.0
],
"metallicFactor": 0.937145713205983,
"roughnessFactor": 0.5
}
},
{
"doubleSided": true,
"extensions": {
"KHR_materials_specular": {
"specularColorFactor": [
1.0,
1.0,
1.0
],
"specularFactor": 1.0
}
},
"name": "Material.003",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.15766773041875703,
0.14889900202474154,
0.14889900202474154,
1.0
],
"roughnessFactor": 0.5
}
},
{
"doubleSided": true,
"extensions": {
"KHR_materials_specular": {
"specularColorFactor": [
1.0,
1.0,
1.0
],
"specularFactor": 1.0
}
},
"name": "Material.002",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.0016820681473392314,
0.7989292457183024,
0.9602083826516892,
1.0
],
"metallicFactor": 0.0,
"roughnessFactor": 0.5
}
}
],
"meshes": [
{
"name": "Object_0",
"primitives": [
{
"attributes": {
"NORMAL": 1,
"POSITION": 0,
"TEXCOORD_0": 2
},
"indices": 3,
"material": 0,
"mode": 4
}
]
},
{
"name": "Object_1",
"primitives": [
{
"attributes": {
"NORMAL": 5,
"POSITION": 4,
"TEXCOORD_0": 6
},
"indices": 7,
"material": 1,
"mode": 4
}
]
},
{
"name": "Object_2",
"primitives": [
{
"attributes": {
"NORMAL": 9,
"POSITION": 8,
"TEXCOORD_0": 10
},
"indices": 11,
"material": 2,
"mode": 4
}
]
}
],
"nodes": [
{
"children": [
1
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
2.220446049250313e-16,
-1.0,
0.0,
0.0,
1.0,
2.220446049250313e-16,
0.0,
0.0,
0.0,
0.0,
1.0
],
"name": "Sketchfab_model"
},
{
"children": [
2
],
"name": "root"
},
{
"children": [
3,
5,
7
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
2.220446049250313e-16,
1.0,
0.0,
0.0,
-1.0,
2.220446049250313e-16,
0.0,
0.0,
0.0,
0.0,
1.0
],
"name": "GLTF_SceneRootNode"
},
{
"children": [
4
],
"matrix": [
0.0,
-1.0,
-0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
4.363928318023682,
1.355409860610962,
-2.9339444637298584,
1.0
],
"name": "Circle.005_1"
},
{
"mesh": 0,
"name": "Object_4"
},
{
"children": [
6
],
"matrix": [
0.0,
-0.05666607618331909,
0.0,
0.0,
0.05666607618331909,
0.0,
0.0,
0.0,
0.0,
0.0,
0.05666607618331909,
0.0,
0.8766956329345703,
2.729276180267334,
2.7074050903320313,
1.0
],
"name": "Cylinder.001_2"
},
{
"mesh": 1,
"name": "Object_6"
},
{
"children": [
8
],
"matrix": [
0.0,
-1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
-0.9677443504333496,
3.4250857830047607,
0.49128252267837524,
1.0
],
"name": "Circle.025_3"
},
{
"mesh": 2,
"name": "Object_8"
}
],
"scene": 0,
"scenes": [
{
"name": "Sketchfab_Scene",
"nodes": [
0
]
}
]
}

View file

@ -0,0 +1,37 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://drrl25ujbosbr"
path="res://.godot/imported/scene.gltf-0f2cf150bf6291a4d643a4542d4a3400.scn"
[deps]
source_file="res://entities/car/tron_moto_lowpoly/scene.gltf"
dest_files=["res://.godot/imported/scene.gltf-0f2cf150bf6291a4d643a4542d4a3400.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1