-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Cooldown should reset automatically when moving to another branch #340
Comments
I don't think what you requested is possible because the cooldown is implemented as a decorator node so, as you correctly identified, it doesn't get the extends ActionLeaf
class_name WaitAction
@export var wait_time: float = 0.0
@onready var cache_key = 'wait_%s' % self.get_instance_id()
func before_run(actor: Node, blackboard: Blackboard) -> void:
blackboard.set_value(cache_key, wait_time, str(actor.get_instance_id()))
func tick(actor: Node, blackboard: Blackboard) -> int:
var remaining_time = blackboard.get_value(cache_key, 0.0, str(actor.get_instance_id()))
if remaining_time > 0.0:
remaining_time -= get_physics_process_delta_time()
blackboard.set_value(cache_key, remaining_time, str(actor.get_instance_id()))
return RUNNING
return SUCCESS
func get_class_name() -> Array[StringName]:
var classes := super()
classes.push_back(&"WaitAction")
return classes
You will need to place this node after your attack node and remove the original cooldown decorator. Also, note that your issue is partially related to #319. While I understand that you're requesting the reset behaviour in particular, the issue you're experiencing is exacerbated by the fact that the cooldown is not ticking down while the cooldown node is not active. This makes the cooldown longer in your case because your cooldown node is not on the behaviour tree's "hot path". |
yes, I could not find a way to implement it with how Beehave is working at the moment. I thought I would flag the issue anyway as it seems reasonable that a Cooldown should reset itself when we leave its branch to go to another branch. As I understand it, the callback |
Same issue with the DelayDecorator. Imagine the following tree where an enemy either attacks the player or patrols an area. When the player enters enemy range, the condition leaf returns
However, the DelayDecorator is never reset to 0 so it restarts from its previously selected child, which seems unintended. I've just started digging into this addon so take my suggestion with a grain of salt, but maybe a new lifecycle method could reset the DelayDecorator when it becomes live? |
Is your feature request related to a problem? Please describe.
When implementing an attack cooldown, we want the enemy to attack immediately the first time, then wait for the cooldown.
However, at the moment, if the selector moves to another behavior the cooldown is not resetted. Thus, when we come back to the Attack sequence, we need to wait for the cooldown to be over for the attack to happen.
See video, the first time the IA goes in
GoToAttack
, the cooldown works as intended. Then I move away, the IA goes toGoToReach
. It reaches me and come back toGoToAttack
. Then, as the cooldown was never resetted, the IA has to wait the cooldown to attack.cooldown.mp4
Note: for the purpose of the video I disable the action
TryStopAttackCooldown
.Describe the solution you'd like
Somehow, when the cooldown is interrupted, it should be resetted.
Describe alternatives you've considered
I played with the
interrupted
andrun_after
, but as the cooldown decorator returns FAILURE, they don't really work for resetting the timer. At the end, I set up aTryStopAttackCooldown
in the another branch that is likely to be selected when the AttackSequence failed.Additional context
Tree with the alternative solution implemented, see
TryStopAttackCooldown
.The text was updated successfully, but these errors were encountered: