summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-04-18 20:59:47 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-04-18 20:59:47 +0200
commit9c918c4a04a656f1017955bcb772ae8ce7c61089 (patch)
treea25e9f416eda5c588be4d98d4869f6c110b34c2c
downloadcar-9c918c4a04a656f1017955bcb772ae8ce7c61089.tar.gz
Working simple car mechanics
-rw-r--r--.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md53
-rw-r--r--.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stexbin0 -> 3493 bytes
-rw-r--r--car.gd15
-rw-r--r--default_env.tres7
-rw-r--r--game.tscn105
-rw-r--r--icon.pngbin0 -> 3446 bytes
-rw-r--r--icon.png.import34
-rw-r--r--project.godot50
8 files changed, 214 insertions, 0 deletions
diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5
new file mode 100644
index 0000000..a111eea
--- /dev/null
+++ b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5
@@ -0,0 +1,3 @@
+source_md5="0167658bc4406f0d0fe437e0197c415a"
+dest_md5="64b0613b3173e1e1c96dd18b6569e62d"
+
diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex
new file mode 100644
index 0000000..002ad14
--- /dev/null
+++ b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex
Binary files differ
diff --git a/car.gd b/car.gd
new file mode 100644
index 0000000..890fc3a
--- /dev/null
+++ b/car.gd
@@ -0,0 +1,15 @@
+extends VehicleBody
+
+var max_rpm = 500
+var max_torque = 200
+
+func _physics_process(delta):
+ var new_steering = (Input.get_action_strength("left")
+ - Input.get_action_strength("right")) * 0.4
+ steering = lerp(steering, new_steering, 5 * delta)
+ var acceleration = (Input.get_action_strength("forward")
+ - Input.get_action_strength("back"))
+ var rpm = $back_left_wheel.get_rpm()
+ $back_left_wheel.engine_force = acceleration * max_torque * (1 - rpm / max_rpm)
+ rpm = $back_right_wheel.get_rpm()
+ $back_right_wheel.engine_force = acceleration * max_torque * (1 - rpm / max_rpm)
diff --git a/default_env.tres b/default_env.tres
new file mode 100644
index 0000000..20207a4
--- /dev/null
+++ b/default_env.tres
@@ -0,0 +1,7 @@
+[gd_resource type="Environment" load_steps=2 format=2]
+
+[sub_resource type="ProceduralSky" id=1]
+
+[resource]
+background_mode = 2
+background_sky = SubResource( 1 )
diff --git a/game.tscn b/game.tscn
new file mode 100644
index 0000000..44b4923
--- /dev/null
+++ b/game.tscn
@@ -0,0 +1,105 @@
+[gd_scene load_steps=9 format=2]
+
+[ext_resource path="res://car.gd" type="Script" id=1]
+
+[sub_resource type="SpatialMaterial" id=1]
+albedo_color = Color( 0.298039, 0.235294, 0.235294, 1 )
+
+[sub_resource type="CubeMesh" id=2]
+material = SubResource( 1 )
+size = Vector3( 50, 1, 50 )
+
+[sub_resource type="ConcavePolygonShape" id=3]
+data = PoolVector3Array( -25, 0.5, 25, 25, 0.5, 25, -25, -0.5, 25, 25, 0.5, 25, 25, -0.5, 25, -25, -0.5, 25, 25, 0.5, -25, -25, 0.5, -25, 25, -0.5, -25, -25, 0.5, -25, -25, -0.5, -25, 25, -0.5, -25, 25, 0.5, 25, 25, 0.5, -25, 25, -0.5, 25, 25, 0.5, -25, 25, -0.5, -25, 25, -0.5, 25, -25, 0.5, -25, -25, 0.5, 25, -25, -0.5, -25, -25, 0.5, 25, -25, -0.5, 25, -25, -0.5, -25, 25, 0.5, 25, -25, 0.5, 25, 25, 0.5, -25, -25, 0.5, 25, -25, 0.5, -25, 25, 0.5, -25, -25, -0.5, 25, 25, -0.5, 25, -25, -0.5, -25, 25, -0.5, 25, 25, -0.5, -25, -25, -0.5, -25 )
+
+[sub_resource type="CubeMesh" id=4]
+size = Vector3( 1.5, 0.5, 3 )
+
+[sub_resource type="ConvexPolygonShape" id=5]
+points = PoolVector3Array( -0.7225, -0.25, -1.43083, -0.7225, -0.25, 1.43083, -0.694167, 0.25, -1.37472, -0.694167, 0.25, 1.37472, 0.694167, 0.25, -1.37472, 0.694167, 0.25, 1.37472, 0.7225, -0.25, -1.43083, 0.7225, -0.25, 1.43083 )
+
+[sub_resource type="CylinderMesh" id=6]
+top_radius = 0.4
+bottom_radius = 0.4
+height = 0.25
+radial_segments = 12
+
+[sub_resource type="SpatialMaterial" id=7]
+albedo_color = Color( 0.156863, 0.160784, 0.290196, 1 )
+
+[node name="game" type="Spatial"]
+
+[node name="ground" type="MeshInstance" parent="."]
+mesh = SubResource( 2 )
+material/0 = null
+
+[node name="StaticBody" type="StaticBody" parent="ground"]
+
+[node name="CollisionShape" type="CollisionShape" parent="ground/StaticBody"]
+shape = SubResource( 3 )
+
+[node name="car" type="VehicleBody" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0 )
+script = ExtResource( 1 )
+
+[node name="car_body" type="MeshInstance" parent="car"]
+mesh = SubResource( 4 )
+material/0 = null
+
+[node name="CollisionShape" type="CollisionShape" parent="car"]
+shape = SubResource( 5 )
+
+[node name="front_left_wheel" type="VehicleWheel" parent="car"]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1 )
+use_as_steering = true
+wheel_radius = 0.4
+suspension_stiffness = 50.0
+damping_compression = 1.9
+damping_relaxation = 2.0
+
+[node name="MeshInstance" type="MeshInstance" parent="car/front_left_wheel"]
+transform = Transform( -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0, 1, 0, 0, 0 )
+mesh = SubResource( 6 )
+material/0 = SubResource( 7 )
+
+[node name="front_right_wheel" type="VehicleWheel" parent="car"]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 1 )
+use_as_steering = true
+wheel_radius = 0.4
+suspension_stiffness = 50.0
+damping_compression = 1.9
+damping_relaxation = 2.0
+
+[node name="MeshInstance" type="MeshInstance" parent="car/front_right_wheel"]
+transform = Transform( -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0, 1, 0, 0, 0 )
+mesh = SubResource( 6 )
+material/0 = SubResource( 7 )
+
+[node name="back_left_wheel" type="VehicleWheel" parent="car"]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, -1 )
+use_as_traction = true
+wheel_radius = 0.4
+suspension_stiffness = 50.0
+damping_compression = 1.9
+damping_relaxation = 2.0
+
+[node name="MeshInstance" type="MeshInstance" parent="car/back_left_wheel"]
+transform = Transform( -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0, 1, 0, 0, 0 )
+mesh = SubResource( 6 )
+material/0 = SubResource( 7 )
+
+[node name="back_right_wheel" type="VehicleWheel" parent="car"]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, -1 )
+use_as_traction = true
+wheel_radius = 0.4
+suspension_stiffness = 50.0
+damping_compression = 1.9
+damping_relaxation = 2.0
+
+[node name="MeshInstance" type="MeshInstance" parent="car/back_right_wheel"]
+transform = Transform( -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0, 1, 0, 0, 0 )
+mesh = SubResource( 6 )
+material/0 = SubResource( 7 )
+
+[node name="Camera" type="Camera" parent="."]
+transform = Transform( 1, 0, 0, 0, 0.934931, 0.35483, 0, -0.35483, 0.934931, 0, 3, 4 )
diff --git a/icon.png b/icon.png
new file mode 100644
index 0000000..2e42096
--- /dev/null
+++ b/icon.png
Binary files differ
diff --git a/icon.png.import b/icon.png.import
new file mode 100644
index 0000000..96cbf46
--- /dev/null
+++ b/icon.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.png"
+dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/project.godot b/project.godot
new file mode 100644
index 0000000..3f62cc4
--- /dev/null
+++ b/project.godot
@@ -0,0 +1,50 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+; [section] ; section goes between []
+; param=value ; assign values to parameters
+
+config_version=4
+
+_global_script_classes=[ ]
+_global_script_class_icons={
+
+}
+
+[application]
+
+config/name="car"
+run/main_scene="res://game.tscn"
+config/icon="res://icon.png"
+
+[input]
+
+forward={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
+ ]
+}
+back={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
+ ]
+}
+left={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
+ ]
+}
+right={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
+ ]
+}
+
+[rendering]
+
+quality/driver/driver_name="GLES2"
+vram_compression/import_etc=true
+vram_compression/import_etc2=false
+environment/default_environment="res://default_env.tres"