Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Need Collision Detection Help

This topic is 6241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm in the process of implementing collision detection in my game engine, and I'm looking for some advise. Here is my situation: My game engine is entirely sprite based, 2d textures mapped onto rectangles. The sprites are scaled and rotated and can move on ALL axis. I need to have collision detection between sprites with the ability to check for collisions within certain parts of a sprite. For example, a man with a sword: I need to define one collision area as the "walk collision" area, where the sprite will stop agaist another object (probably a rectangle by his feet). I also need to define a "target collision" area, where the sprite will take damage if hit (probably a rectangle/polygon surrounding the body). And finally a "attack collision" area, where the sprite will give damage to an object if hit (the sprite's weapon). At this point I'm thinking of defining 3 polygons per sprite frame that determine these collision areas. That's fine, but how should I go about checking for collision in these areas? If the sprite is scaled or rotated the sprite frames collision polygons must go through the same transformations, otherwise the collisions will be incorrect. Any suggestions as to where I should start? Thanks, Ian Edited by - ion497 on August 14, 2001 7:36:11 PM

Share this post

Link to post
Share on other sites
Ok, I'm no expert but it seems to me like you have two options. The first is to use polygons like you said, make each one up from a series of lines and check for collisions between every pair of lines in the two polygons you're checking. This would be very time consuming (collisions between 2 triangles would require 9 checks) and would not detect if one polygon was entirely enclosed in the other. The alternative is to chose a center point for each object and create an array storing the radius of an arc for each section of the circle (the larger the array the more precise you can make the shape).

If you can't see what I'm getting at, imagine two circles, one inside the other. Draw a big cross through both circles and remove the other arcs at the two sides and the inner arcs at the top and bottom - there, you have a (very rough) oval. Store the radius of the larger circle in an array at indexs 0 and 2 and the radius of the smaller circle at index 1 and 3.

Then all you need to do is to find the distance between the centres of the two objects, and the angle that the line between them makes with the vertical. Use the angles to look up the radius at that angle for each object and add the two radius's together. If they come to more than the distance between the two objects then you have a collision. Scaling & rotation are also no problem, just multiply the value from the array to scale & add to the angle before lookup to rotate. If you need to rotate in 3 dimesions, then you'll need to take the angle and radius at that angle, split it into components along your axis and multiply each component by the sine of the angle rotated through before recombining.

Hope that helps.

Edited by - Enigma on August 17, 2001 3:15:12 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!