-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1f41f34
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[gd_scene load_steps=6 format=2] | ||
|
||
[ext_resource path="res://src/old/Ground.tscn" type="PackedScene" id=1] | ||
[ext_resource path="res://src/old/Plane.tscn" type="PackedScene" id=2] | ||
[ext_resource path="res://src/CameraTutorial/PlaneController.gd" type="Script" id=3] | ||
|
||
[sub_resource type="SpatialMaterial" id=1] | ||
albedo_color = Color( 0.988235, 0.545098, 0.027451, 1 ) | ||
|
||
[sub_resource type="CubeMesh" id=2] | ||
material = SubResource( 1 ) | ||
size = Vector3( 1, 1, 1 ) | ||
|
||
[node name="Main" type="Node"] | ||
|
||
[node name="World" type="Spatial" parent="."] | ||
|
||
[node name="Scene" type="Spatial" parent="World"] | ||
|
||
[node name="Ground" parent="World/Scene" instance=ExtResource( 1 )] | ||
|
||
[node name="Box" type="MeshInstance" parent="World/Scene"] | ||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.79738, 0.5, 8.04267 ) | ||
mesh = SubResource( 2 ) | ||
material/0 = null | ||
|
||
[node name="Box2" type="MeshInstance" parent="World/Scene"] | ||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 8.25432, 0.5, -5.78508 ) | ||
mesh = SubResource( 2 ) | ||
material/0 = null | ||
|
||
[node name="Box3" type="MeshInstance" parent="World/Scene"] | ||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 22.0821, 0.5, 15.5209 ) | ||
mesh = SubResource( 2 ) | ||
material/0 = null | ||
|
||
[node name="Box4" type="MeshInstance" parent="World/Scene"] | ||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 22.0821, 0.5, -18.3429 ) | ||
mesh = SubResource( 2 ) | ||
material/0 = null | ||
|
||
[node name="Box5" type="MeshInstance" parent="World/Scene"] | ||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -26.3151, 0.5, 9.66531 ) | ||
mesh = SubResource( 2 ) | ||
material/0 = null | ||
|
||
[node name="Box6" type="MeshInstance" parent="World/Scene"] | ||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -11.7818, 0.5, -14.251 ) | ||
mesh = SubResource( 2 ) | ||
material/0 = null | ||
|
||
[node name="PlaneController" type="Camera" parent="World"] | ||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 19.946, 51.1794 ) | ||
script = ExtResource( 3 ) | ||
speed = 20.0 | ||
yaw_speed = 40.0 | ||
max_yaw = 40.0 | ||
max_roll = 90.0 | ||
pitch_speed = 40.0 | ||
|
||
[node name="Plane" parent="World/PlaneController" instance=ExtResource( 2 )] | ||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, -3 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
extends Camera | ||
|
||
|
||
######################### | ||
# EXPORT PARAMS | ||
######################### | ||
# speed | ||
export (float, 1, 100) var speed = 10 | ||
export (float, 1, 3, 0.1) var turbo_modifier = 2 | ||
# yaw | ||
export (float, 1, 100) var yaw_speed = 10 | ||
export (float, 10, 180, 1) var max_yaw = 70 | ||
# roll | ||
export (float, 10, 180, 1) var max_roll = 70 | ||
export (float, 1, 100) var pitch_speed = 10 | ||
# pitch | ||
export (float, 10, 180, 1) var max_pitch = 30 | ||
export (float, 3, 10, 0.5) var turbo_time = 5 | ||
|
||
|
||
######################### | ||
# PARAMS | ||
######################### | ||
onready var model = $Plane | ||
|
||
|
||
######################### | ||
# OVERRIDE FUNCTIONS | ||
######################### | ||
func _process(delta: float) -> void: | ||
_move(delta) | ||
_pitch(delta) | ||
_yaw(delta) | ||
|
||
|
||
######################### | ||
# MOVEMENT FUNCTIONS | ||
######################### | ||
func _move(delta: float) -> void: | ||
translation -= transform.basis.z * delta * speed | ||
|
||
|
||
func _pitch(delta: float) -> void: | ||
var mouse_speed = _get_mouse_speed() | ||
rotation_degrees.x += mouse_speed.y * delta * pitch_speed | ||
var amount = abs(mouse_speed.y) | ||
var direction = sign(mouse_speed.y) | ||
model.rotation_degrees.x = lerp(0, max_pitch, amount) * direction | ||
|
||
|
||
func _yaw(delta: float) -> void: | ||
var mouse_speed = _get_mouse_speed() | ||
rotation_degrees.y += mouse_speed.x * delta * pitch_speed | ||
_roll_and_yaw_model(mouse_speed.x, delta) | ||
|
||
|
||
func _roll_and_yaw_model(mouse_speed_x: float, delta: float) -> void: | ||
var amount = abs(mouse_speed_x) | ||
var direction = sign(mouse_speed_x) | ||
model.rotation_degrees.y = lerp(0, max_yaw, amount) * direction | ||
model.rotation_degrees.z = lerp(0, max_roll, amount) * direction | ||
|
||
######################### | ||
# HELPER FUNCTIONS | ||
######################### | ||
func _get_mouse_speed() -> Vector2: | ||
var screen_center = get_viewport().size * 0.5 | ||
var displacment = screen_center - get_viewport().get_mouse_position() | ||
displacment.x /= screen_center.x | ||
displacment.y /= screen_center.y | ||
return displacment | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|