Skip to main content
gamedev.net
🔒 Locked

collision detection

Started by kiznore Apr 28, 2004 at 8:57 AM 0 replies 500+ views
Original Post
kiznore
kiznore
Hi ya Im having a problem with my collsion detection in my 2D space shooter. Im trying to do simple collsion detection. The game is based on asteroids so you get the idea of wht the game is like. I have made my asteroid very round to help me in my collsion detection. I was wondering if you let me know if this is right. What i do is get the length of the line between the bullet and asteroid using the equation -> length = the squareroot(x2-x1)squared * (y2-y1)squared -> and then if this length is smaller than the asteroids radius then theres collsion. Is this right. Any other suggestion. Thank you
Skizz
Skizz
It''s:
l = sqrt ((x2-x1)^2 + (y2-y1)^2)
where ''a^b'' is raise a to the power of b. More efficent is:
l_sq = (x2-x1)^2 + (y2-y1)^2
and test l_sq against the square of the collision distance.
Also, the collision distance is the sum of the asteroid''s radius and the player''s radius.
A more accurate method is to use collision maps.

Skizz

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.