Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
p5.Vector.prototype.mult: x, y, or z arguments are either undefined or not a finite number
    updateVelocity(allBodies, timeStep){
        for (let otherBody of allBodies) {



            if(otherBody != this){                
                let sqrDst = (p5.Vector.sub(otherBody.pos, this.pos).mag());
                let forceDir = (p5.Vector.sub(otherBody.pos, this.pos).normalize());
                let force = p5.Vector.mult(forceDir, gravity * this.mass * otherBody.mass / sqrDst);
                let acceleration = p5.Vector.div(force, this.mass);
                this.currentVelocity.add(acceleration * timeStep);
            }
        }
    }


    updatePosition(timeStep){
        this.pos.add(this.currentVelocity * timeStep);
        ellipse(this.pos.x, this.pos.y, this.radius);
    }
}

I am trying to replicate Sebastian Lague's solar system video but with p5.js

I am getting this error p5.Vector.prototype.mult: x, y, or z arguments are either undefined or not a finite number. When I remove the line where i multiply it disapears but that makes the whole thing not work. I looked it up and it could be that the z value is automatically 0, but i tried setting it manually to 1 by adding and it still didnt work.

I did some debugging and found out that the force actually changes but as the planets dont move it stays the same after a while and nothing happens.

How do i get rid of this error?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Console log forceDir. I suspect one of the vector components is infinity (or undefined).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!