![]() |
Programming Hit Detection
How would one go about doing this? I know how to calculate if 2 circles collide using distance, and boxes colliding using if the 2 items are within each other.
But how the heck would I code collision detection from scratch using items using a rotated box? Can someone explain in pseudo code or c++? |
Are you talking 3D or 2D?
Or just mathematically speaking? |
If distx is 0 and disty is 0 then hit
|
Here's a small C++ code I've forked off, it's just hit detection for circles, though you get the concept hopefully.
PHP Code:
|
Are you using any libraries? Typically they will provide you with methods to detect collisions between shapes.
|
Quote:
Quote:
Quote:
I guess the problem I'm having is that i can't mathematically figure out if two objects collide. Let's say for example you have one rectangle that is constantly rotating, and your character using a circular(or square) hitbox). How would you detect collision between the two? The distance formula wouldn't work, as it is not only circles. |
Quote:
|
As long as the hit box it good enough for the player to hit it without a trick shot, it's good.
|
Quote:
|
Quote:
I found this, if you're curious on reading: http://seb.ly/2009/05/super-fast-tri...rsection-test/ There's a lot you can probably find on shape collision on google. The languages might be different but the logic is always the same. I mean, it sounds like you're dealing with some complicated interactions(balls and rotating rectangles and such), if you're interested in doing even some basic physics stuff involving these objects interacting it might be beneficial looking into a library that will help you out. Anyways, if you want to try to start working it out yourself, then imo the first thing I would do is work out whether a single point(your mouse) is within a shape. After that, you just need to create bounding shapes out of a group of these points. |
|
All times are GMT. The time now is 03:04 PM. |
Powered by vBulletin/Copyright ©2000 - 2025, vBulletin Solutions Inc.