mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 23:10:08 +01:00
* General proofreading for grammar and spelling * General formatting * Addition of appropriate literals where appropriate, i.e. `&"foo"` for `StringName` cases and `^"foo/bar"` for `NodePath` cases
29 lines
1013 B
GDScript
29 lines
1013 B
GDScript
extends Node3D
|
|
|
|
var open := false
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event.is_action_pressed(&"toggle_doors"):
|
|
if open:
|
|
# Close the door.
|
|
# The occluder will be re-enabled when the animation ends
|
|
# using `_on_animation_player_animation_finished()`.
|
|
$AnimationPlayer.play_backwards(&"open")
|
|
open = false
|
|
else:
|
|
# Open the door.
|
|
$AnimationPlayer.play(&"open")
|
|
open = true
|
|
# Disable the occluder as soon as the door starts opening.
|
|
# The occluder is not part of the pivot to prevent it from having its
|
|
# position changed every frame, which causes the occlusion culling BVH
|
|
# to be rebuilt each frame. This causes a CPU performance penalty.
|
|
$OccluderInstance3D.visible = false
|
|
|
|
|
|
func _on_animation_player_animation_finished(_anim_name: StringName) -> void:
|
|
if not open:
|
|
# Re-enable the occluder when the door is done closing.
|
|
# To prevent overocclusion, the door must be fully closed before the occluder can be re-enabled.
|
|
$OccluderInstance3D.visible = true
|