Skip to content
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

Add better documentation to explain the purpose of interrupts #264

Open
SavoVuksan opened this issue Dec 4, 2023 · 3 comments
Open

Add better documentation to explain the purpose of interrupts #264

SavoVuksan opened this issue Dec 4, 2023 · 3 comments
Labels
📙 docs Improvements or additions to documentation

Comments

@SavoVuksan
Copy link

This is not really a but more a question regarding interrupts. How do they work? Do they work implicity when a BT changes the Composite or do I need to call it directly in one of my leaf nodes?

I am trying to create an enemy AI with a BT. The enemy should aim at the player as soon as they are in sight. The aim action runs forever as long as the player is in-sight. As soon as they leave it should go into the waitforever action where we wait until the player gets in sight again.
image

I think I would need interrupts here. But I am not quite sure since I am pretty new to BT.

Does anybody have a plan if I am understanding interrupts correctly/BT?

@SavoVuksan SavoVuksan added the 🐛 bug Something isn't working label Dec 4, 2023
@bitbrain bitbrain changed the title How does interrupt work? Add documentation to explain how interrupts work Dec 4, 2023
@bitbrain bitbrain added 📙 docs Improvements or additions to documentation and removed 🐛 bug Something isn't working labels Dec 4, 2023
@bitbrain
Copy link
Owner

bitbrain commented Dec 4, 2023

Hey @SavoVuksan - thanks for raising this. We probably should have a dedicated section in the wiki about interrupts, as they can be confusing at first.

The general idea behind interrupts is that you may have a running action but suddenly that 'branch' will not get visited any longer, so now you end up with a 'running' action that actually does not run any longer. In case that happens, beehave will propagate 'down the tree' and interrupt everything before proceeding to the new branch.

What you need in your example is not interrupts (as interrupts are more of an internal working) but instead, you should utilise conditions

Basically like this (pseudo-code):

AimTargetSelector <-- should be selector, so only 1st condition is ever executed if true
   PlayerLostSequence
      InverterDecorator
         IsTargetInRangeAreaCondition
      WaitAction <-- this gets run each frame, so no need to wait 'forever' but just... wait
      LostEmoteAction
   PlayerFoundSequence
      ... the rest of it

The idea is that this tree gets executed every frame. In case the target is not in range, the player lost sequence will just play. It is critical here to make the parent a 'selector', as we only want to execute the 'PlayerFoundSequence' in case the 'PlayerLostSequence' fails.

@bitbrain bitbrain changed the title Add documentation to explain how interrupts work Add better documentation to explain the purpose of interrupts Dec 4, 2023
@SavoVuksan
Copy link
Author

Ok, thanks for clarifying how interrupts work. Regarding your pseudo code example. The WaitAction would be a running action as long as the condition !isTargetInRange is active. Otherwise, the emote would play all the time. Am I right?

@peterpants2
Copy link

That's helpful as I also wondered if Interrupts were more performant that using Conditions as I imagined they were signal based. It sounds similar to a sort of 'reset' track for animations. i.e. return the action to a particular state upon interruption

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📙 docs Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants