ige icon indicating copy to clipboard operation
ige copied to clipboard

Changing speed on an active path causes entity to suddenly skip forwards/backwards

Open beyond-code-github opened this issue 6 years ago • 3 comments

Provision seems to have been made for changing speed on an active path, whereby we stop() it and then restart, passing the original start time so it is treated as one seamless traversal.

https://github.com/Irrelon/ige/blob/d02bbda99f8b0fe331c6465b5225be27da1efb7c/engine/components/IgePathComponent.js#L338

The cause of the bug is that we only consider the current speed vs time when determining where an entity should be along the path, even though the path ran for a certain time at a different speed:

https://github.com/Irrelon/ige/blob/d02bbda99f8b0fe331c6465b5225be27da1efb7c/engine/components/IgePathComponent.js#L527

I've got around this in my codebase by overriding the speed method to simply stop the path altogether and restart as a completely new traversal, but I don't fully understand the implications for other use cases. I'm happy to raise a PR if it's acceptable. Example here (forgive the ES2017 😄):

if (this._active) {
    this.stop();

    const startPoint = this._entity._parent.pointToTile(this._entity._translate);
    const endPoint = this.getEndPoint();

    this.set(startPoint.x, startPoint.y, startPoint.z, endPoint.x, endPoint.y, endPoint.z);
    this.start();
}

beyond-code-github avatar Mar 13 '18 10:03 beyond-code-github

Hmm. Yeah I remember that you could at some point in the past successfully change the speed along a path and it did work - or at least that is my recollection!

I guess the only issue I can think of here is if there is a hook on a stopped event and we call stop and then start again... any event listeners would fire if events are emitted for those actions?

The way around that would be to have a flag called something like "this._emitEvents = true" and then set that to false before executing the code above and then back to true after executed so we bypass any event emitting for this specific case?

Irrelon avatar Mar 13 '18 10:03 Irrelon

(Then obviously wrap any emit calls in an if, or something like:

this._emitEvents && this.emit('started', blah);

Irrelon avatar Mar 13 '18 10:03 Irrelon

Wow, has it really been 6 months since we discussed this!? Just wanted to let you know that I have finally arrived at a satisfactory implementation for this and will raise a PR over the next few days 👍

beyond-code-github avatar Sep 26 '18 20:09 beyond-code-github