Jump to content
  • Advertisement
Sign in to follow this  
shrek

Collision detection

This topic is 5145 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

I am trying to make a 2d side scroller but the graphics are such that the tiles used for blocking some are complete 32 * 32 and the graphics occupy the whole tile are but some occupy just on half or more but not complete. How do I check collision dectection. Please help

Share this post


Link to post
Share on other sites
Advertisement
I'm not really in the place to put my thoughts down, but this should get you what you need. It's often just a matter of knowing the terminology.

Searching these forums for the same (and just collision detection) will get you plenty of detailed responses.

Also, this may come in handy, if you're doing any bullet ricochets etc.

Lastly, the articles on this site, specifically the Collision Detection ones should help you out.

Share this post


Link to post
Share on other sites
Nice and easy if you're dealing with rectangles. Test each corner point of one rectangle against the destination.

Here's the basic collision detection code from jsInvaders. It only reports if the two collision boxes overlap, further tests such as per pixel tests can be done after this to fine tune the collision.



// Simple test to see if collision box of WeaponFire (wf) intersects with collision box of alien

// bl = bottom left, tl = top left, tr = top right, tl = top left


vMin.x = alien->collisionbox.bl.x;
vMin.y = alien->collisionbox.bl.y;

vMax.x = alien->collisionbox.tr.x;
vMax.y = alien->collisionbox.tr.y;

//compare collisions
if (( wf->collisionbox.tr.x >= vMin.x ) && ( wf->collisionbox.tr.x <= vMax.x ) )
{
// matches in the x
if (( wf->collisionbox.br.y >= vMin.y ) && ( wf->collisionbox.br.y <= vMax.y ) )
{
/// A COLLISION HAS HAPPENED

}
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!