My latest project involves creating an object that moves randomly in a natural way using noise, which is working perfectly:
However, when the objects collide and their trajectory changes to a straight line, I want them to return to moving randomly as before. If I use the same function, the object jumps back to its last location before the trajectory change.
thisObject.x = _world.width * (noise(thisObject.t));
thisObject.y = _world.height * (noise(thisObject.t+5));
thisObject.t += 0.001;
let vx = this.acquiredFood[0] - this.x;
let vy = this.acquiredFood[1] - this.y;
let f = (this.genes.speed + 10) / Math.sqrt(vx*vx+vy*vy);
vx = vx * f;
vy = vy * f;
let newX = this.x + vx;
let newY = this.y + vy;
I am looking for a solution to get the object to move as it did initially from a specific starting position.
Edit: code snippet can be found here: