![]() |
|
03-05-2014
|
1 |
|
The Unwanted Critic
Join Date: Sep 2011
Posts: 3,639
|
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++? |
|
03-05-2014
|
2 |
|
299,792,458 m/s
Join Date: Mar 2012
Location: Lebanon
Posts: 3,581
|
Are you talking 3D or 2D? Or just mathematically speaking? |
|
03-05-2014
|
3 |
|
Banned
Join Date: Sep 2012
Posts: 1,059
|
If distx is 0 and disty is 0 then hit
|
|
03-05-2014
|
4 |
|
299,792,458 m/s
Join Date: Mar 2012
Location: Lebanon
Posts: 3,581
|
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:
|
|
03-05-2014
|
5 |
|
Should be fixed.
Join Date: Aug 2011
Posts: 6,359
|
Are you using any libraries? Typically they will provide you with methods to detect collisions between shapes.
|
|
03-06-2014
|
6 | |
|
The Unwanted Critic
Join Date: Sep 2011
Posts: 3,639
|
2d.
That only works for rectangular hotboxes. Doesn't work for a rotated plane. 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. |
|
|
03-06-2014
|
7 |
|
Should be fixed.
Join Date: Aug 2011
Posts: 6,359
|
|
|
03-07-2014
|
8 |
|
Banned
Join Date: Aug 2013
Location: The hood.
Posts: 3,167
|
As long as the hit box it good enough for the player to hit it without a trick shot, it's good.
|
|
03-07-2014
|
9 |
|
The Unwanted Critic
Join Date: Sep 2011
Posts: 3,639
|
|
|
03-07-2014
|
10 | |
|
Should be fixed.
Join Date: Aug 2011
Posts: 6,359
|
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. |
|