Closed MxAshUp closed 4 years ago
I also noticed that PathParticle ignores acceleration. But this may be expected behavior. However adding acceleration support for PathParticle could be easy (this is tested and works):
// PathParticle.update()
// ...
if(this._doSpeed) {
const speed = this.speedList.interpolate(lerp) * this.speedMultiplier;
this.movement += speed * delta;
} else {
// Adapted from Particle.update()
if (this._doAcceleration) {
this.velocity.x += this.acceleration.x * delta;
this.velocity.y += this.acceleration.y * delta;
if (this.maxSpeed) {
var currentSpeed = ParticleUtils.length(this.velocity);
if (currentSpeed > this.maxSpeed) {
ParticleUtils.scaleBy(this.velocity, this.maxSpeed / currentSpeed);
}
}
}
const speed = ParticleUtils.length(this.velocity);
this.movement += speed * delta;
}
// ...
Maybe open a feature request for it?
Ignoring acceleration is intentional - PathParticles are supposed to move in an exact path, and being affected by gravity/wind would interfere with that. Merely changing this.movement
would be different behavior than what acceleration does to normal particles, and basically duplicates what interpolating speed
values does.
Background It took me a while to get the ParticlePath working, but following the example code I finally got it, with one exception: when I had the speed set to no interpolation (ie start speed = end speed) I got an error "TypeError: this.next is null".
How to reproduce
Solution I've debugged the code enough to understand the cause. In PathParticle here: https://github.com/pixijs/pixi-particles/blob/master/src/PathParticle.ts#L153, the code assumes speedList needs to be interpolated. I think the solution involves first checking if
this._doSpeed
is true. If I understand PathParticle correctly the fix should look something like this:EDIT: Workaround For anyone seeing this issue and needing a workaround (providing this isn't closed yet), I recommend setting speed start and end to nearly the same value, for example:
I'll get a PR started