Should be able to interrupt and "splice" actions into action queue
See original GitHub issueThink about the AI pathing we did for Kraken. What if in the update loop I wanted to have the ship randomly “look back” and then return back to what it was going to do (moveTo).
I should be able to do something like this using action API:
lookbackTimer: number = 500;
update(engine, delta): void {
if (this.lookbackTimer <= 0) {
var actions = [
new RotateBy(...), // look back
new RotateBy(...) // return back to original
};
this.actionQueue.queueAfterCurrentAction(actions, interrupt: true/false);
}
this.lookbackTimer -= delta;
}
Essentially allow me to insert actions into the queue as it’s being processed but also allow me to choose whether I want to wait until the current action is done or interrupt immediately (cancel) and then resume again later. In the case I’m talking about, I’d want to wait until the current rotation/moveTo is done, then lookback, then reverse lookback, then resume action queue. However I could also see interrupting a moveTo (for example in the middle), doing the lookback actions, then resuming the moveTo from where it left off (pause/resume).
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:11 (10 by maintainers)
Top GitHub Comments
@LePhil Definitely a bug. I think I know what the problem here is, and I definitely would expect your test case to be true.
Basically actions don’t handle large update values or update boundaries well 😦 before the next action can activate, a frame must elapse. Basically it is only possible for 1 action to complete per frame (update) given the current implementation.
Normally updates fire at 60FPS (every ~16ms) so at run time things “mostly” work although the accumulated error piles up quickly, see codepen https://codepen.io/eonarheim/pen/LOJeQe?editors=0010
Here is a snippet of the
ActionQueue
update, and it only concerns itself with the current action and if it completes.With a slightly modified version of your test and excalibur that logs delta and position it’s very clear:
Console out:
I think the correct way to fix this is to retool the existing actions api to accurately position actors after updates and calculate the time each action should take.
I have a hack of the
moveBy
action that seems to work by moving the target actor immediately to the position rather than setting velocity. And it passes the test you provided https://github.com/excaliburjs/Excalibur/tree/bugfix-actionqueue.This issue hasn’t had any recent activity lately and is being marked as stale automatically.