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

Attempting to loop over the full behavior tree #46

Closed
dobrite opened this issue Aug 5, 2015 · 2 comments
Closed

Attempting to loop over the full behavior tree #46

dobrite opened this issue Aug 5, 2015 · 2 comments

Comments

@dobrite
Copy link

dobrite commented Aug 5, 2015

Still trying to wrap my head around how this all works. I've read the blog post, read the gamasutra article, looked at sea birds and also the implementation of the this library. This isn't an issue with the library (thanks for all your work btw!) but likely an issue with how I am using it.

I have the following behavior tree defined which is just a really simple proof of concept. Action::Down moves a unit down one square, and Action::Up moves a unit up one square. I'm looking for a way for the behavior tree to continuously "loop" and have the unit move up and down. I'd like for the root of the tree to always be running, if that makes sense.

Are Sequences one shot ordeals? I'm assuming that they get reset but they seem to get stuck on the last behavior (in this case continuing to move down).

Any help would be appreciated, and again, thanks for all the libraries!

let behavior = While(Box::new(WaitForever), vec![Sequence(vec![
    Action(Action::Down), Action(Action::Up)
])]);
@bvssvni
Copy link
Member

bvssvni commented Aug 5, 2015

While should loop the body as long as the condition is running. If it gets stuck on the last behavior it might be a bug, or it could be that no time is consumed for update events.

When updating an object's position you have to tell the behavior tree how much time it took. This is called "consuming time". If the same consumed time is returned, the actions will behave as instant. Return the consumed time of what you want to simulate, for example, if you get 0.1 seconds and hit a wall in 0.04 seconds and the action HitWall succeeds, then you subtract 0.1 - 0.04 = 0.06 and give that back to the behavior tree.

You need a Wait behavior to consume time if the actions are instant (does not consume time and return the same amount of seconds they receive). When an action executes, it returns a tuple (status, dt_time_left). If the dt_time_left is 0, then the behavior tree will return and pause until next event. If the dt_time_left is greater than zero, it will try execute the next action.

When a loop gets stuck it is likely to be the case that no time is consumed by any action.

@dobrite
Copy link
Author

dobrite commented Aug 13, 2015

'm returning (ai_behavior::Success, 0.0) which should alternate between up and down. It enters a forever loop (freezes the game) once it hits the end of the sequence.

I am using it a bit different from the sea birds example. I am cloning the state, running the event,
then sending off the resulting state to later assigned to the entity. This state comes back around
and is cloned... etc. I don't think this is the issue, but probably am wrong.

Again, thanks for taking the time to look at my issue!

let mut state = ai.state.clone();
state.event(e, &mut |action_args| {
    send.send(event::Event::Movement {
        entity: entity,
        dir: match *action_args.action {
            Action::Down => dir::Dir::Down,
            Action::Up => dir::Dir::Up,
        }
    });
    (ai_behavior::Success, 0.0)
});
send.send(event::Event::UpdateAiState { entity: entity, state: state.clone() });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants