libgdx / gdx-ai

Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parallel task repeats other tasks.

lukz opened this issue · comments

Is it intended for parallel task to repeat all tasks until all tasks return success condition or one return fail condition (depending on policy)?

I want to make a monster which starts to move and at the same time shoot 5 times. Movement can take a lot longer than shooting. No matter how I construct this parallel task monster is shooting constantly until movement task is finished or stop moving after finishing shooting.

To demonstrate:

root
  sequence
    parallel policy:"sequence"
      sequence
        wait seconds:0.3f
        log text:"TASK1"
      log text:"TASK2"
    log text:"END"
    wait seconds:10

(Log task returns SUCCESS instantly after execution)

This is output:

GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK2
GDXAI: TASK1
GDXAI: TASK2
GDXAI: END
commented

In short Yes, parallel task will repeat all tasks (it restarts completed tasks).

For your case, you need an extra task to know when to stop shooting (when not moving). It could be something like this :

root
  sequence
    parallel policy:"sequence"
      sequence
        wait seconds:0.3f
        log text:"TASK1 (move finished)"
      sequence
        repeat times:5
          log text:"TASK2 (shoot once)"
        waitIdleState
    log text:"END"
    wait seconds:10

where "waitIdleState" is returning :

  • SUCCESS when monster is not moving
  • RUNNING otherwise.

@mgsx-dev this seems to break whole idea of reusing tasks in BT without additional code. I guess I'll just replace parallel task with my own one ;)

@lukz
What if you wrap the shoot task with a custom decorator alwaysRunning that always returns STATUS_RUNNING regardless of child's status?
Actually, I think that this kind of decorator might be part of the framework.
PR welcome 😃

@lukz
I think that commit f747fbd implements exactly what you asked for, see PR #93
The wiki should be updated soon.
Let me know if it's enough for your needs.
Closing this.