commit d947ffdb5e9fea293cd48fe5622654e44cb5e22e
parent 6f1b2c74860b069d1e149d058ae8788c2a8b7f00
Author: FIGBERT <figbert@figbert.com>
Date: Tue, 24 Nov 2020 17:51:39 -0800
Update code for fourth section of Godot tutorial
Diffstat:
4 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/Level.tscn b/Level.tscn
@@ -1,7 +1,8 @@
-[gd_scene load_steps=8 format=2]
+[gd_scene load_steps=9 format=2]
[ext_resource path="res://scenes/Character.tscn" type="PackedScene" id=1]
[ext_resource path="res://scripts/Character.gd" type="Script" id=2]
+[ext_resource path="res://scripts/Camera.gd" type="Script" id=3]
[sub_resource type="BoxShape" id=1]
@@ -10,11 +11,11 @@
[sub_resource type="BoxShape" id=3]
extents = Vector3( 15, 1, 15 )
-[sub_resource type="SpatialMaterial" id=5]
+[sub_resource type="SpatialMaterial" id=4]
albedo_color = Color( 0.0392157, 0.933333, 0.682353, 1 )
-[sub_resource type="CubeMesh" id=4]
-material = SubResource( 5 )
+[sub_resource type="CubeMesh" id=5]
+material = SubResource( 4 )
size = Vector3( 30, 2, 30 )
[node name="Level" type="Spatial"]
@@ -37,12 +38,21 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
shape = SubResource( 3 )
[node name="MeshInstance" type="MeshInstance" parent="Floor"]
-mesh = SubResource( 4 )
+mesh = SubResource( 5 )
material/0 = null
-[node name="Camera" type="Camera" parent="."]
-transform = Transform( 1, 0, 0, 0, 0.851398, 0.524521, 0, -0.524521, 0.851398, 0, 4.91959, 10.0583 )
-
[node name="Character" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
script = ExtResource( 2 )
+
+[node name="Viewport" type="Spatial" parent="Character"]
+transform = Transform( 1, 0, 0, 0, 0.930884, 0.365315, 0, -0.365315, 0.930884, 0, 3.25256, 10.2951 )
+
+[node name="Camera" type="Camera" parent="."]
+transform = Transform( 1, 0, 0, 0, 0.851398, 0.524521, 0, -0.524521, 0.851398, 0, 9.91959, 19.0583 )
+script = ExtResource( 3 )
+
+[node name="DirectionalLight" type="DirectionalLight" parent="."]
+transform = Transform( 0.866025, -0.433013, -0.25, 0, -0.5, 0.866025, -0.5, -0.75, -0.433013, 0, 6.37746, 0 )
+shadow_enabled = true
+directional_shadow_max_distance = 50.0
diff --git a/default_env.tres b/default_env.tres
@@ -1,6 +1,8 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
+ground_bottom_color = Color( 0.411765, 0.760784, 0.94902, 1 )
+ground_horizon_color = Color( 0.839216, 0.917647, 0.980392, 1 )
[resource]
background_mode = 2
diff --git a/project.godot b/project.godot
@@ -18,6 +18,12 @@ _global_script_class_icons={
config/name="Basic Move and Dodge Game"
config/icon="res://icon.png"
+[display]
+
+window/size/width=1280
+window/size/height=720
+window/dpi/allow_hidpi=true
+
[input]
ui_left={
diff --git a/scripts/Camera.gd b/scripts/Camera.gd
@@ -0,0 +1,20 @@
+extends Camera
+
+const translate_speed := 0.5
+const rotate_speed := 0.95
+const fov_speed := 0.95
+const near_far_speed := 0.95
+
+func _ready():
+ pass
+
+func _process(delta):
+ var translate_factor: float = translate_speed * delta * 10
+ var rotate_factor: float = rotate_speed * delta * 10
+ var target_node := get_node(@"../Character/Viewport")
+ var target_xform: Transform = target_node.get_global_transform()
+ var local_transform_only_origin := Transform(Basis(), get_global_transform().origin)
+ var local_transform_only_basis := Transform(get_global_transform().basis, Vector3())
+ local_transform_only_origin = local_transform_only_origin.interpolate_with(target_xform, translate_factor)
+ local_transform_only_basis = local_transform_only_basis.interpolate_with(target_xform, rotate_factor)
+ set_global_transform(Transform(local_transform_only_basis.basis, local_transform_only_origin.origin))