2d_in_3d.gd 807 B

123456789101112131415161718192021222324
  1. extends Node3D
  2. ## Camera idle scale effect intensity.
  3. const CAMERA_IDLE_SCALE = 0.005
  4. var counter := 0.0
  5. @onready var camera_base_rotation: Vector3 = $Camera3D.rotation
  6. func _ready() -> void:
  7. # Clear the viewport.
  8. var viewport: SubViewport = $SubViewport
  9. viewport.render_target_clear_mode = SubViewport.CLEAR_MODE_ONCE
  10. # Retrieve the texture and set it to the viewport quad.
  11. $ViewportQuad.material_override.albedo_texture = viewport.get_texture()
  12. func _process(delta: float) -> void:
  13. # Animate the camera with an "idle" animation.
  14. counter += delta
  15. $Camera3D.rotation.x = camera_base_rotation.y + cos(counter) * CAMERA_IDLE_SCALE
  16. $Camera3D.rotation.y = camera_base_rotation.y + sin(counter) * CAMERA_IDLE_SCALE
  17. $Camera3D.rotation.z = camera_base_rotation.y + sin(counter) * CAMERA_IDLE_SCALE