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

198
Vistas
Is there a way to detect collisions between the ball and the lines?

I'm currently working on a little physics simulation, and had some trouble figuring out how to get the ball to collide with the platforms. Here's my code:

var a, f = 0.95, s = 0, vx = 0, vy = 0, b = -0.6, m = 10, x = 200, y = 100;

function setup() {
  createCanvas(400, 400);
  
  a = m * 0.1;
}

function draw() {
  background(100);
  
  line(0, 100, 200, 210);
  
  line(400, 100, 150, 320);
  
  //friction and acceleration stuff
  vx *= f;
  x += vx;
  vy += a;
  y += vy;
  
  //wall collisions
  if (y >= height - 12) {
    vy *= b;
    y = height - 12;
  }
  if (y < 12) {
    y = 12;
  }
  if (x > width - 12) {
    vx *= b;
    x = width - 12;
  }
  if (x < 12) {
    vx *= b;
    x = 12;
  }

  ellipse(x, y, 24);
  
  //snapping position to mouse
  if(mouseIsPressed)
    {
      s = (winMouseX - pwinMouseX)/4;
      x = mouseX;
      y = mouseY;
      vx += s;
      vy = 0;
    }
  
}

<script src="https://cdn.jsdelivr.net/npm/p5@1.4.1/lib/p5.js"></script>

My main issues come from not knowing how to deal with slopes, so if anyone has an idea it would be much appreciated. Thanks!

about 4 years ago · Juan Pablo Isaza
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