Add basic buggy controls

soundtrack
Ensar Sarajčić 2021-11-05 23:11:26 +01:00
parent e5138be1c2
commit 0f8561636d
10 changed files with 1239 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +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 )

View File

@ -2,33 +2,35 @@
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
path.s3tc="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.stex"
path.etc2="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex"
metadata={
"vram_texture": false
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.stex", "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex" ]
[params]
compress/mode=0
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/repeat=true
flags/filter=true
flags/mipmaps=false
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=2
flags/srgb=1
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
detect_3d=false
svg/scale=1.0

32
player/camera.gd 100644
View File

@ -0,0 +1,32 @@
extends Camera
export (NodePath) var follow_target_path = null
export var target_distance: float = 3.0
export var target_height: float = 2.0
var follow_target: Node = null
var last_lookat: Vector3
# Called when the node enters the scene tree for the first time.
func _ready():
follow_target = get_node(follow_target_path)
last_lookat = follow_target.global_transform.origin
func _physics_process(delta):
var delta_v = global_transform.origin - follow_target.global_transform.origin
var target_pos = global_transform.origin
delta_v.y = 0.0
if (delta_v.length() > target_distance):
delta_v = delta_v.normalized() * target_distance
delta_v.y = target_height
target_pos = follow_target.global_transform.origin + delta_v
else:
target_pos.y = follow_target.global_transform.origin.y + target_height
global_transform.origin = global_transform.origin.linear_interpolate(target_pos, delta * 20.0)
last_lookat = last_lookat.linear_interpolate(follow_target.global_transform.origin, delta * 20.0)
look_at(last_lookat, Vector3(0.0, 1.0, 0.0))

View File

@ -0,0 +1,37 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://vehicles/buggy.tscn" type="PackedScene" id=1]
[ext_resource path="res://player/camera.gd" type="Script" id=2]
[ext_resource path="res://icon.png" type="Texture" id=3]
[sub_resource type="PlaneMesh" id=1]
[sub_resource type="SpatialMaterial" id=3]
albedo_texture = ExtResource( 3 )
[sub_resource type="ConcavePolygonShape" id=2]
data = PoolVector3Array( 1, 0, 1, -1, 0, 1, 1, 0, -1, -1, 0, 1, -1, 0, -1, 1, 0, -1 )
[node name="Spatial" type="Spatial"]
[node name="StaticBody" type="StaticBody" parent="."]
transform = Transform( 99.9785, 0, 0, 0, 99.9785, 0, 0, 0, 99.9785, 0, 0, 0 )
[node name="MeshInstance" type="MeshInstance" parent="StaticBody"]
transform = Transform( 6.13726, 0, 0, 0, 6.13726, 0, 0, 0, 6.13726, 0, 0, 0 )
mesh = SubResource( 1 )
material/0 = SubResource( 3 )
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
transform = Transform( 6.13726, 0, 0, 0, 6.13726, 0, 0, 0, 6.13726, 0, 0, 0 )
shape = SubResource( 2 )
[node name="buggy" parent="." instance=ExtResource( 1 )]
transform = Transform( 1.00456, 0, 0, 0, 1.00456, 0, 0, 0, 1.00456, -0.0204048, 0.0478153, -0.0235357 )
[node name="camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.88022, 23.0639 )
script = ExtResource( 2 )
follow_target_path = NodePath("../buggy")
target_distance = 12.0
target_height = 6.0

39
vehicles/buggy.gd 100644
View File

@ -0,0 +1,39 @@
extends VehicleBody
const STEER_SPEED = 1.5
const STEER_LIMIT = 0.4
var steer_target = 0
export var engine_force_value = 40
func _physics_process(delta):
var fwd_mps = transform.basis.xform_inv(linear_velocity).x
steer_target = Input.get_action_strength("ui_left") - Input.get_action_strength("ui_right")
steer_target *= STEER_LIMIT
if Input.is_action_pressed("ui_up"):
# Increase engine force at low speeds to make the initial acceleration faster.
var speed = linear_velocity.length()
if speed < 5 and speed != 0:
engine_force = clamp(engine_force_value * 5 / speed, 0, 100)
else:
engine_force = engine_force_value
else:
engine_force = 0
if Input.is_action_pressed("ui_down"):
# Increase engine force at low speeds to make the initial acceleration faster.
if fwd_mps >= -1:
var speed = linear_velocity.length()
if speed < 5 and speed != 0:
engine_force = -clamp(engine_force_value * 5 / speed, 0, 100)
else:
engine_force = -engine_force_value
else:
brake = 1
else:
brake = 0.0
steering = move_toward(steering, steer_target, STEER_SPEED * delta)

View File

@ -0,0 +1,55 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/basic_buggy.glb" type="PackedScene" id=1]
[ext_resource path="res://vehicles/buggy.gd" type="Script" id=3]
[sub_resource type="BoxShape" id=1]
extents = Vector3( 2.46457, 1, 1.77811 )
[node name="buggy" instance=ExtResource( 1 )]
script = ExtResource( 3 )
[node name="chassis" parent="." index="0"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
[node name="left_front" parent="." index="2"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.33227, 0.952938, -2.92949 )
use_as_traction = true
use_as_steering = true
wheel_roll_influence = 0.2
wheel_rest_length = 0.5
suspension_travel = 0.5
suspension_stiffness = 3.0
suspension_max_force = 12000.0
[node name="right_front" parent="." index="3"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.33227, 0.952938, -2.92949 )
use_as_traction = true
use_as_steering = true
wheel_roll_influence = 0.2
wheel_rest_length = 0.5
suspension_travel = 0.5
suspension_stiffness = 3.0
suspension_max_force = 12000.0
[node name="rear_left" parent="." index="4"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.33227, 0.952938, 2.92949 )
use_as_traction = true
wheel_roll_influence = 0.2
wheel_rest_length = 0.5
suspension_travel = 0.5
suspension_stiffness = 3.0
suspension_max_force = 12000.0
[node name="rear_right" parent="." index="5"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.33227, 0.952938, 2.92949 )
use_as_traction = true
wheel_roll_influence = 0.2
wheel_rest_length = 0.5
suspension_travel = 0.5
suspension_stiffness = 3.0
suspension_max_force = 12000.0
[node name="CollisionShape" type="CollisionShape" parent="." index="6"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.36968, 0 )
shape = SubResource( 1 )