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

239
Views
El código se "omite" al comprobar si hay colisión

Estoy creando un juego para un proyecto escolar y necesito verificar cuando un jugador choca con una pared, pero la función que he escrito solo funciona para un lado del rectángulo.

 function wallCollision(){ if (player.x + player.l > wall.x && player.x < wall.x + wall.width){ if (player.y == wall.y + wall.height){ player.velocity.negy = 0; } if (player.y + player.l == wall.y){ player.velocity.posy = 0; } } if (player.y < wall.y + wall.height && player.y + player.l > wall.y){ if (player.x == wall.x + wall.width){ player.velocity.negx = 0; } if (player.x + player.l == wall.x){ player.velocity.posy = 0; } } }

Cuando lo ejecuto, solo funciona cuando verifico la identificación, el jugador chocó en el lado izquierdo de la pared.

 if (player.x == wall.x + wall.width){ player.velocity.negx = 0; }

y cuando traté de console.log dentro de los otros 3 ifs anidados, descubrí que el código nunca se ejecuta

Intenté reorganizar la función pero no funcionó completamente o de alguna manera fue peor.

neg y pos se refieren a la dirección en los ejes x e y, por lo que posx = 0 significa que el jugador no puede moverse a la derecha, negx = 0 que no puede moverse let, posy = 0 que no puede ir hacia abajo y negy = 0 que no puede moverse hacia arriba

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