Page 1 of 1

SOLVED Collision help!

Posted: Sat Jan 11, 2014 10:54 pm
by MysticPing2
So i am trying to make something happen when this spaceship hits an asteroid (and make asteroids kill eachother if they hit eachother) But to do this i need to detect colissions, and i have tried this, many, many times in different ways. Now i give up.

The current method of collision is in src/Starship.lua
(which does not work properly at all)

Re: Collision help!

Posted: Sun Jan 12, 2014 10:15 am
by micha
You forgot height and width of the astroids. This is your code:

Code: Select all

if starship.x <= v.x and v.x >= starship.x + starship.width and starship.y >= v.y and v.y <= starship.y + starship.height then
this is how it should be (I also reversed some of the comparisons):

Code: Select all

if starship.x <= v.x + v.width and v.x <= starship.x + starship.width and starship.y <= v.y + v.height and v.y <= starship.y + starship.height then