Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

312
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda