Skip to content

Commit

Permalink
Add some scaling to the camera rotation test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinw committed Apr 18, 2024
1 parent 3f0baa4 commit f143ce1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=12 format=3 uid="uid://bwxt880aodsau"]
[gd_scene load_steps=15 format=3 uid="uid://bwxt880aodsau"]

[ext_resource type="Script" path="res://examples/camera_rotation/test_camera_rotation.gd" id="1_qkm28"]
[ext_resource type="PackedScene" uid="uid://biunegs8tkvn0" path="res://addons/godot_vision/VisionVolumeCamera.tscn" id="1_voaop"]
[ext_resource type="Texture2D" uid="uid://bmd0x5t1c2b3i" path="res://examples/hello/textures/checker.jpg" id="3_rolhg"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_c0ixi"]
albedo_color = Color(0, 0, 1, 1)
Expand Down Expand Up @@ -35,6 +36,15 @@ size = Vector3(1, 0.5, 0.1)
[sub_resource type="BoxMesh" id="BoxMesh_cmp3s"]
size = Vector3(0.3, 0.3, 0.3)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nyu35"]
albedo_texture = ExtResource("3_rolhg")
uv1_scale = Vector3(3, 3, 3)
uv1_offset = Vector3(2.08165e-12, 2.08165e-12, 2.08165e-12)

[sub_resource type="BoxMesh" id="BoxMesh_f6g3q"]
material = SubResource("StandardMaterial3D_nyu35")
size = Vector3(3, 0.05, 3)

[node name="CameraRotationExample" type="Node3D"]
script = ExtResource("1_qkm28")

Expand Down Expand Up @@ -72,3 +82,7 @@ mesh = SubResource("BoxMesh_cmp3s")

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.760995, 0.293167, -0.57874, 1.86432e-16, 0.892074, 0.45189, 0.648758, -0.343886, 0.678864, 0, 0, 0)

[node name="Floor" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.08165e-12, -0.5, 2.08165e-12)
mesh = SubResource("BoxMesh_f6g3q")
25 changes: 18 additions & 7 deletions Godot_Project/examples/camera_rotation/test_camera_rotation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,37 @@ extends Node3D

@onready var cam_node: Node3D = $VisionVolumeCamera


const pos_changes := [Vector3(0, 0, 1), Vector3(1, 0, 0), Vector3(0, 0, -1), Vector3(-1, 0, 0)]

func _ready():
await get_tree().create_timer(1.0).timeout
await timeout(1)

var rot: Vector3 = Vector3(0, 0, 0)
var pos: Vector3 = Vector3(0, 0, 0)

var pos_changes := [Vector3(0, 0, 1), Vector3(1, 0, 0), Vector3(0, 0, -1), Vector3(-1, 0, 0)]
var pos_change_index := 0

while true:
rot += Vector3(0, 0.5 * PI, 0)
await tween_prop(cam_node, "scale", Vector3(1, 1, 1) * 0.3, 0.5)
await timeout(0.6)
await tween_prop(cam_node, "scale", Vector3(1, 1, 1) * 1.0, 0.5)
await timeout(0.6)

rot += Vector3(0, 0.5 * PI, 0)
pos += pos_changes[pos_change_index] * 4
pos_change_index = (pos_change_index + 1) % pos_changes.size()

await create_tween().tween_property(cam_node, "rotation", rot, 0.5).set_ease(Tween.EASE_IN_OUT).finished
await get_tree().create_timer(0.5).timeout
await create_tween().tween_property(cam_node, "position", pos, 0.5).set_ease(Tween.EASE_OUT_IN).finished
await get_tree().create_timer(1.0).timeout
await tween_prop(cam_node, "rotation", rot, 0.5)
await timeout(0.5)
await tween_prop(cam_node, "position", pos, 0.5)
await timeout(0.5)


func timeout(amt: float):
await get_tree().create_timer(amt).timeout

func tween_prop(node: Node3D, prop_name: String, value, duration: float):
await create_tween().tween_property(node, prop_name, value, duration).set_ease(Tween.EASE_IN_OUT).finished


0 comments on commit f143ce1

Please sign in to comment.