Collision Detection function



Hey I’m trying to create a collision detection function for a simple planet obstacle game. The spaceship should detect the planets. The planets are overlayed with invisible boxes with id’s 1-9 in order of distance from the sun. I have already created the function to move the spaceship. Thanks in advance.
Project: (594.7 KB)

(Mark Hunte) #2


What are you asking here?


I need a JavaScript function for my spaceship to detect when it is hit by the planets


I’m asking for a collision detection function

(Greg) #5

A few questions and suggestions

  1. What purpose do the invisible boxes have?

  2. What is supposed to happen if you detect a collision?

  3. It’s considered bad practice to name elements with a number

  4. The spin is set pretty fast, it’s hard to see what is happening on the webpage - maybe you can stretch the timelines to slow it down a bit.

Here’s a sample of an action started from a collision, I’m not sure it will work from a keyboard action (arrow keys) (13.0 KB)


The bounding boxes on the planets are larger than the actual planet so I made the boxes to fit the planet. If you detect a collision a simple warning will work