Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

311
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda