-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bi-directional door animations #16
Comments
Here's the GDScript code I wrote to implement this logic: extends Node3D
@onready var animation = $AnimationPlayer
enum { CLOSED, CLOSING, OPENING, OPEN }
var door_state = CLOSED
var in_outside_area = false
var in_inside_area = false
var closing_animation = ""
func check_door_state():
match door_state:
CLOSED:
if in_outside_area:
door_state = OPENING
animation.play("open_inward")
closing_animation = "open_inward"
elif in_inside_area:
door_state = OPENING
animation.play("open_outward")
closing_animation = "open_outward"
OPENING:
pass
CLOSING:
pass
OPEN:
if !in_outside_area and !in_inside_area:
door_state = CLOSING
animation.play_backwards(closing_animation)
func _on_animation_player_animation_finished(anim_name):
match door_state:
OPENING:
door_state = OPEN
CLOSING:
door_state = CLOSED
check_door_state()
func _on_outside_area_3d_body_entered(body):
if body is CharacterBody3D:
in_outside_area = true
check_door_state()
func _on_outside_area_3d_body_exited(body):
if body is CharacterBody3D:
in_outside_area = false
check_door_state()
func _on_inside_area_3d_body_entered(body):
if body is CharacterBody3D:
in_inside_area = true
check_door_state()
func _on_inside_area_3d_body_exited(body):
if body is CharacterBody3D:
in_inside_area = false
check_door_state() |
Thanks for this. That being said: I understand the request was able to add this functionality to COGITO in a different way. You can see how it works here: 2024-01-07.09-04-13.mp4I'll include this script in the next update, but if you want to give it a try earlier, here it is (with automatic signal hookup): door_setter_zone.gd
|
Looks great. I do like the option to have automatic doors too. |
I've added a quick update to door_setter_zone.gd which enables it to be used to set up automatic doors in experimental / BETA 202401.7 Ideally this script would be used to either update doors and their directions OR be used to create the automatic behaviour, due to how the zone signals get fired. If you want to create a door that is automatic but also changes directions, I'd handle this in separate door_setter_zones that overlap:
Considering this issue as resolved. |
Thanks for making this happen! |
I've been working with these house assets and realized that the default animations it uses which open a door when a player character is nearby are a bit awkward to use when the doors open toward the character. Toward that end, I've prototyped a solution that I would love to see incorporated into Cogito, if possible. You can see what it looks like in this mastodon post.
The main idea would be to have the door swing inward if approached from one side, and outward from the other. I implemented this by adding another Area3D to determine which side the of the door the player is approaching from, and managing a simple state machine to run the animations.
The text was updated successfully, but these errors were encountered: