PDA

View Full Version : Best way to approach Collision detection



Zion
July 20th, 2006, 22:43
Now that i have finished my animation code (finally...lol) I am going to make a collision code.

Now, i know how to do the map collision (stopping player falling of the screen) but am wondering about the best and easyest to add to way of doing things such as object and enemy ai collision.

If you have any advice on the best way to approach it, that would be great. :D

BTW, this isn't for Future-Resurection, It's for a secret game im coding! :p

No details on it yet, but expect it to be big! :D

hopefully it will be out in about 1 or 2 months! And fully playable :D

yaustar
July 21st, 2006, 20:46
Falling off the edge of the map or edge of the physical screen?

The easiest method for the latter is to set a bounding area:

if sprite.x < 0 then
sprite.x = 0
elseif (sprite.x + sprite.width) > screen.width then
sprite.x = screen.width - sprite.width
end

if sprite.y < 0 then
sprite.y = 0
elseif (sprite.y + sprite.height) > screen.height then
sprite.y = screen.height - sprite.height
end

Edit: misread post. for the enemy to player, box collision will suffice. See my example code in the Dev forums.