Add different cameras and cockpits #1

Merged
esensar merged 3 commits from post-jam into main 2022-01-19 14:54:33 +00:00
38 changed files with 266 additions and 13 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,43 @@
class_name CameraController
extends Reference
const FOLLOW_CAMERA = preload("res://player/cameras/follow_camera.tscn")
const STATIC_CAMERA = preload("res://player/cameras/static_camera.tscn")
var _cameras = []
func attach_cameras_to(player_node: BuggedVehicle) -> void:
var cockpit_camera = STATIC_CAMERA.instance()
player_node.get_cockpit_position().add_child(cockpit_camera)
cockpit_camera.rotate(Vector3.UP, deg2rad(180))
var follow_camera = FOLLOW_CAMERA.instance()
follow_camera.global_transform = player_node.global_transform.translated(
-player_node.global_transform.basis.z * 100
)
follow_camera.follow_target_path = player_node.get_path()
player_node.get_parent().add_child(follow_camera)
var bumpera_camera = STATIC_CAMERA.instance()
player_node.get_bumper_position().add_child(bumpera_camera)
bumpera_camera.rotate(Vector3.UP, deg2rad(180))
var hood_camera = STATIC_CAMERA.instance()
player_node.get_hood_position().add_child(hood_camera)
hood_camera.rotate(Vector3.UP, deg2rad(180))
var static_follow_camera = STATIC_CAMERA.instance()
player_node.get_static_follow_position().add_child(static_follow_camera)
static_follow_camera.rotate(Vector3.UP, deg2rad(180))
_cameras = [follow_camera, cockpit_camera, hood_camera, bumpera_camera, static_follow_camera]
select_camera(GlobalSettings.selected_camera)
func select_camera(camera_index: int) -> void:
var select_index = camera_index
if camera_index < 0 or camera_index >= _cameras.size():
select_index = 0
GlobalSettings.selected_camera = select_index
_cameras[select_index].current = true
func next_camera() -> void:
select_camera(GlobalSettings.selected_camera + 1)

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://player/camera.gd" type="Script" id=1]
[ext_resource path="res://player/cameras/follow_camera.gd" type="Script" id=1]
[node name="camera" type="Camera"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.88022, 23.0639 )

View File

@ -0,0 +1,4 @@
[gd_scene format=2]
[node name="camera" type="Camera"]
far = 1000.0

View File

@ -19,6 +19,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://vehicles/vehicle.gd"
}, {
"base": "Reference",
"class": "CameraController",
"language": "GDScript",
"path": "res://player/cameras/camera_controller.gd"
}, {
"base": "Particles",
"class": "TireSmoke",
"language": "GDScript",
@ -32,6 +37,7 @@ _global_script_classes=[ {
_global_script_class_icons={
"BaseTrackLevel": "",
"BuggedVehicle": "",
"CameraController": "",
"TireSmoke": "",
"Track": ""
}
@ -124,6 +130,12 @@ reset_vehicle={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
]
}
next_camera={
"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":70,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":2,"pressure":0.0,"pressed":false,"script":null)
]
}
[physics]

View File

@ -1,10 +1,11 @@
class_name BaseTrackLevel
extends Spatial
const CAMERA = preload("res://player/camera.tscn")
const CAMERA_CONTROLLER = preload("res://player/cameras/camera_controller.gd")
var player_node: Node
var player_node: BuggedVehicle
var gui: Node
var camera_controller: CameraController
onready var track = $Track
@ -13,15 +14,11 @@ func _ready() -> void:
reset_player_to(track.get_furthest_checkpoint(), player_node)
add_child(player_node)
add_child(gui)
var player_camera = CAMERA.instance()
player_camera.global_transform = player_node.global_transform.translated(
-player_node.global_transform.basis.z * 100
)
player_camera.follow_target_path = player_node.get_path()
add_child(player_camera)
camera_controller = CAMERA_CONTROLLER.new()
camera_controller.attach_cameras_to(player_node)
func spawn_player(player_node: Node, gui: Node) -> void:
func spawn_player(player_node: BuggedVehicle, gui: Node) -> void:
self.player_node = player_node
self.gui = gui
@ -40,6 +37,9 @@ func _process(_delta: float) -> void:
if Input.is_action_just_released("reset_vehicle"):
reset_player_to(track.get_furthest_checkpoint(), player_node)
if Input.is_action_just_released("next_camera"):
camera_controller.next_camera()
func _on_ResetArea_body_entered(body: Node) -> void:
if body.get_groups().has("car"):

View File

@ -2,3 +2,4 @@ extends Node
var auto_clutch: bool = false
var automatic_transmission: bool = true
var selected_camera: int = 0

View File

@ -1,8 +1,11 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=16 format=2]
[ext_resource path="res://vehicles/vehicle.gd" type="Script" id=1]
[ext_resource path="res://assets/beetlecar.glb" type="PackedScene" id=2]
[ext_resource path="res://vehicles/tire_smoke.tscn" type="PackedScene" id=3]
[ext_resource path="res://vehicles/pedal.gd" type="Script" id=4]
[ext_resource path="res://vehicles/meter.gd" type="Script" id=5]
[ext_resource path="res://vehicles/steering_controller.gd" type="Script" id=6]
[sub_resource type="Curve" id=3]
_data = [ Vector2( 0, 0 ), 0.0, 3.60634, 0, 1, Vector2( 0.15566, 0.561364 ), 1.56017, 1.56017, 0, 0, Vector2( 0.830189, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
@ -70,6 +73,26 @@ suspension_stiffness = 12.0
damping_compression = 0.75
damping_relaxation = 0.8
[node name="brake_pedal" parent="chassis/cockpit" index="0"]
script = ExtResource( 4 )
[node name="clutch_pedal" parent="chassis/cockpit" index="1"]
script = ExtResource( 4 )
[node name="gas_pedal" parent="chassis/cockpit" index="2"]
script = ExtResource( 4 )
[node name="rpm_meter" parent="chassis/cockpit" index="3"]
script = ExtResource( 5 )
needle_path = NodePath("rpm_needle")
[node name="speed_meter" parent="chassis/cockpit" index="4"]
script = ExtResource( 5 )
needle_path = NodePath("speed_needle")
[node name="steering_controller" parent="chassis/cockpit" index="5"]
script = ExtResource( 6 )
[node name="rear_left" parent="." index="3"]
transform = Transform( 1, 0, 0, 0, 1, -1.50996e-07, 0, 1.50996e-07, 1, 0.621506, 0.375, -0.83483 )
use_as_traction = true
@ -139,3 +162,22 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.621508, 0.0502438, 1.19336
[node name="fl_tire_smoke" parent="." index="12" instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, -1.50996e-07, 0, 1.50996e-07, 1, 0.621506, 0.0502438, 1.19336 )
[node name="cockpit" type="Position3D" parent="." index="13"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.122976, 1.13133, 0.315432 )
[node name="hood" type="Position3D" parent="." index="14"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.01256, 0.87905 )
[node name="bumper" type="Position3D" parent="." index="15"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.535274, 1.89154 )
[node name="static_follow" type="Position3D" parent="." index="16"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.59115, -3.01375 )
[connection signal="brake_updated" from="." to="chassis/cockpit/brake_pedal" method="_on_value_updated"]
[connection signal="clutch_updated" from="." to="chassis/cockpit/clutch_pedal" method="_on_value_updated"]
[connection signal="rpm_updated" from="." to="chassis/cockpit/rpm_meter" method="_on_value_updated"]
[connection signal="speed_updated" from="." to="chassis/cockpit/speed_meter" method="_on_value_updated"]
[connection signal="steering_updated" from="." to="chassis/cockpit/steering_controller" method="_on_steering_updated"]
[connection signal="throttle_updated" from="." to="chassis/cockpit/gas_pedal" method="_on_value_updated"]

View File

@ -1,8 +1,11 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=16 format=2]
[ext_resource path="res://assets/basic_buggy.glb" type="PackedScene" id=1]
[ext_resource path="res://vehicles/tire_smoke.tscn" type="PackedScene" id=2]
[ext_resource path="res://vehicles/vehicle.gd" type="Script" id=3]
[ext_resource path="res://vehicles/steering_controller.gd" type="Script" id=4]
[ext_resource path="res://vehicles/meter.gd" type="Script" id=5]
[ext_resource path="res://vehicles/pedal.gd" type="Script" id=7]
[sub_resource type="Curve" id=2]
_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.0660377, 0.243255 ), 0.0, 0.0, 0, 0, Vector2( 0.25, 0.563636 ), 4.02975, 4.02975, 0, 0, Vector2( 0.518868, 0.761364 ), 3.22818, 3.22818, 0, 0, Vector2( 0.849057, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
@ -58,6 +61,33 @@ sound_curve = SubResource( 4 )
automatic_gear_up_threshold = 0.85
automatic_gear_down_threshold = 0.4
[node name="brake_pedal" parent="chassis/cockpit" index="0"]
script = ExtResource( 7 )
[node name="clutch_pedal" parent="chassis/cockpit" index="1"]
script = ExtResource( 7 )
[node name="gas_pedal" parent="chassis/cockpit" index="2"]
script = ExtResource( 7 )
[node name="rpm_meter" parent="chassis/cockpit" index="3"]
transform = Transform( 1, 0, 0, 0, 0.351842, 0.93606, 0, -0.93606, 0.351842, 0.036114, 0.360487, 0.695986 )
script = ExtResource( 5 )
needle_path = NodePath("rpm_needle")
[node name="rpm_needle" parent="chassis/cockpit/rpm_meter" index="0"]
transform = Transform( 1, 0, 0, 0, 0.351842, -0.93606, 0, 0.93606, 0.351842, -0.000453245, 0.000504017, -0.00276601 )
[node name="speed_meter" parent="chassis/cockpit" index="4"]
script = ExtResource( 5 )
needle_path = NodePath("speed_needle")
[node name="speed_needle" parent="chassis/cockpit/speed_meter" index="0"]
transform = Transform( 1, 0, 0, 0, 0.351841, -0.93606, 0, 0.93606, 0.351841, -0.00056617, 0.000744879, -0.00399888 )
[node name="steering_controller" parent="chassis/cockpit" index="5"]
script = ExtResource( 4 )
[node name="front_left" parent="." index="1"]
use_as_traction = true
use_as_steering = true
@ -139,3 +169,22 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.950753, -0.0380455, -1.41438
[node name="rr_tire_smoke" parent="." index="12" instance=ExtResource( 2 )]
transform = Transform( 1, 0, 0, 0, 1, -1.50996e-07, 0, 1.50996e-07, 1, -0.950755, -0.038045, -1.41438 )
[node name="cockpit" type="Position3D" parent="." index="13"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.44962, 0.200323 )
[node name="hood" type="Position3D" parent="." index="14"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.31056, 0.894584 )
[node name="bumper" type="Position3D" parent="." index="15"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.811448, 1.79879 )
[node name="static_follow" type="Position3D" parent="." index="16"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.15146, -4.84184 )
[connection signal="brake_updated" from="." to="chassis/cockpit/brake_pedal" method="_on_value_updated"]
[connection signal="clutch_updated" from="." to="chassis/cockpit/clutch_pedal" method="_on_value_updated"]
[connection signal="rpm_updated" from="." to="chassis/cockpit/rpm_meter" method="_on_value_updated"]
[connection signal="speed_updated" from="." to="chassis/cockpit/speed_meter" method="_on_value_updated"]
[connection signal="steering_updated" from="." to="chassis/cockpit/steering_controller" method="_on_steering_updated"]
[connection signal="throttle_updated" from="." to="chassis/cockpit/gas_pedal" method="_on_value_updated"]

View File

@ -1,8 +1,11 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=18 format=2]
[ext_resource path="res://vehicles/tire_smoke.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/bugmobile.glb" type="PackedScene" id=2]
[ext_resource path="res://vehicles/vehicle.gd" type="Script" id=3]
[ext_resource path="res://vehicles/steering_controller.gd" type="Script" id=4]
[ext_resource path="res://vehicles/pedal.gd" type="Script" id=5]
[ext_resource path="res://vehicles/meter.gd" type="Script" id=6]
[sub_resource type="Curve" id=18]
_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.179245, 0.584091 ), 4.91185, 4.91185, 0, 0, Vector2( 0.603774, 0.954545 ), 6.05975, 6.05975, 0, 0, Vector2( 0.806604, 0.989773 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
@ -89,6 +92,26 @@ suspension_max_force = 7000.0
damping_compression = 0.9
damping_relaxation = 0.92
[node name="brake_pedal" parent="chassis/cockpit" index="0"]
script = ExtResource( 5 )
[node name="clutch_pedal" parent="chassis/cockpit" index="1"]
script = ExtResource( 5 )
[node name="gas_pedal" parent="chassis/cockpit" index="2"]
script = ExtResource( 5 )
[node name="steering_controller" parent="chassis/cockpit" index="3"]
script = ExtResource( 4 )
[node name="rpm_meter" parent="chassis/cockpit/steering_controller" index="0"]
script = ExtResource( 6 )
needle_path = NodePath("rpm_needle")
[node name="speed_meter" parent="chassis/cockpit/steering_controller" index="1"]
script = ExtResource( 6 )
needle_path = NodePath("speed_needle")
[node name="front_right" parent="." index="4"]
use_as_steering = true
wheel_radius = 0.35
@ -138,3 +161,22 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.18159, 0.117865, -1.93644 )
[node name="rr_tire_smoke" parent="." index="12" instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, -1.50996e-07, 0, 1.50996e-07, 1, -1.02536, 0.101852, -1.93766 )
[node name="cockpit" type="Position3D" parent="." index="13"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.03657, 0 )
[node name="hood" type="Position3D" parent="." index="14"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.00873, 0.756477 )
[node name="bumper" type="Position3D" parent="." index="15"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.605405, 1.5324 )
[node name="static_follow" type="Position3D" parent="." index="16"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.88984, -4.78212 )
[connection signal="brake_updated" from="." to="chassis/cockpit/brake_pedal" method="_on_value_updated"]
[connection signal="clutch_updated" from="." to="chassis/cockpit/clutch_pedal" method="_on_value_updated"]
[connection signal="rpm_updated" from="." to="chassis/cockpit/steering_controller/rpm_meter" method="_on_value_updated"]
[connection signal="speed_updated" from="." to="chassis/cockpit/steering_controller/speed_meter" method="_on_value_updated"]
[connection signal="steering_updated" from="." to="chassis/cockpit/steering_controller" method="_on_steering_updated"]
[connection signal="throttle_updated" from="." to="chassis/cockpit/gas_pedal" method="_on_value_updated"]

12
vehicles/meter.gd 100644
View File

@ -0,0 +1,12 @@
extends MeshInstance
export(float) var min_angle = -90
export(float) var max_angle = 90
export(NodePath) var needle_path = null
func _on_value_updated(_value: int, value_percent: float) -> void:
get_node(needle_path).rotation.y = -(
deg2rad(min_angle)
+ value_percent * deg2rad(max_angle - min_angle)
)

View File

@ -0,0 +1,8 @@
extends MeshInstance
export(float) var min_angle = 0
export(float) var max_angle = 45
func _on_value_updated(value_percent: float) -> void:
rotation.x = -(deg2rad(min_angle) + value_percent * deg2rad(max_angle - min_angle))

View File

@ -0,0 +1,11 @@
extends MeshInstance
export(float) var max_steer_angle = 90
func update_angle(steering_angle_percent: float) -> void:
rotation.z = deg2rad(max_steer_angle) * steering_angle_percent
func _on_steering_updated(_steering_angle: float, steering_angle_percent: float) -> void:
update_angle(steering_angle_percent)

View File

@ -3,7 +3,11 @@ extends VehicleBody
signal speed_updated(speed_kph, speed_percent)
signal rpm_updated(rpm, rpm_percent)
signal throttle_updated(throttle_percent)
signal brake_updated(brake_percent)
signal clutch_updated(clutch_percent)
signal gear_updated(gear)
signal steering_updated(steering_angle, steering_percent)
export(float) var max_steer_angle = 25
export(float) var speed_steer_angle = 10
@ -47,6 +51,11 @@ onready var flsmoke: TireSmoke = $fl_tire_smoke
onready var rrsmoke: TireSmoke = $rr_tire_smoke
onready var rlsmoke: TireSmoke = $rl_tire_smoke
onready var cockpit: Position3D = $cockpit
onready var hood: Position3D = $hood
onready var bumper: Position3D = $bumper
onready var static_follow: Position3D = $static_follow
onready var engine_sound_player: AudioStreamPlayer3D = $engine_sound_player
onready var engine_sound_playback: AudioStreamPlayback = $engine_sound_player.get_stream_playback()
@ -66,6 +75,22 @@ func _ready():
engine_sound_player.play()
func get_cockpit_position() -> Node:
return cockpit
func get_hood_position() -> Node:
return hood
func get_bumper_position() -> Node:
return bumper
func get_static_follow_position() -> Node:
return static_follow
func _integrate_forces(state: PhysicsDirectBodyState) -> void:
if reset_transform != Transform.IDENTITY:
state.linear_velocity = Vector3.ZERO
@ -184,6 +209,9 @@ func _physics_process(delta: float):
var final_input = transmission_input * final_drive
emit_signal("throttle_updated", throttle)
emit_signal("brake_updated", brake_input)
emit_signal("clutch_updated", clutch_position)
brake = brake_input * max_brake_force
engine_force = throttle * final_input * max_engine_force
@ -210,6 +238,7 @@ func _physics_process(delta: float):
var steer_speed_factor = clamp(speed / max_steer_speed, 0.0, 1.0)
steering = steering_input * lerp(max_steer_angle_rad, speed_steer_angle_rad, steer_speed_factor)
emit_signal("steering_updated", steering, steering / max_steer_angle_rad)
func _generate_engine_sound(rpm_factor):