Hello, nice to meet you, no matter who you are.:D
I tried to make a 360 degree collision box.
But it's not good.
It has a strange range of judgment.
As you can see, I use the vector distance of two coordinates.And these heights and widths.
--------------------------------------------------
I have two questions:
Except for //Incomplete content.Is it right to do this?
If it is wrong, where is it?
Please help me.
This is a simple collision detection function I came up with. Rather than checking if two objects overlap, it tests if they do not. This goes against what we would normally do, but it is faster. It checks if the left edge of one box (it's minimum X co-ordinate) is greater than the right edge of another (it's maximum X co-ordinate), than the two cannot be colliding and returns false right away. It does the same for the vertical Y co-ordinates, if the top of one box (minimum Y co-ordinate) is greater than the bottom of another box (maximum Y co-ordinate) than it is impossible for the two to be colliding.
If either of those two tests are true, you can return immediately from this function with a false, or no collision which makes it much faster as most of the time, your objects will not be colliding and you don't want your program hanging around in a function for more time than it needs to.
If BOTH of those tests fail, than you absolutely have a collision and can return true, or process it even further to figure out where they are colliding if needed.
In this example code, I send it the information from a C++ Pong game I made, with the position of the ball and the paddle.
This is of course, simple bounding box collision.
For circular collision, this is code I use in my Deluxe Pacman 2 game (link below). Ignore the hack detection code, I put that in there so that if someone hacked my game to cheat (and someone did), than my game would alter itself and make it more difficult to play without making it immediately apparent that it detected the hack. This is originally intended as pure C code, not C++. Not much of a difference, but just so you understand why I use pointers * in this and references & in the bounding box above. You can't use references like the above in C functions... (just to be clear)...
@Neil Roy
Thanks for your help.:)
Although, the problem has been solved before.
But your plan is a feature.
Here's a little demo of collision between two bouncers. The circle lights up when they are in circle collision, and the rectangles light up when they are in rectangle collision.
Bounce.zip (src + static win32 binary)
{"name":"611210","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/0\/406980faaea33a30144813ad19902e66.png","w":802,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/0\/406980faaea33a30144813ad19902e66"}
Collision between two AABB's or two circles is easy.
Edit
https://www.allegro.cc/forums/thread/596331/747956#target
This might be nice to try for collision resolution
Very nice example Edgar! Simple and efficient.
I've got working circle based intercept collision. In the past, I had intercept collision code for rectangles too. That must be around here somewhere.
I just can't quite get my collision response correct, which is what I'm working on atm.
I think you have a good way of doing it.(*゚∀゚*)
Although I'm more pragmatic.
Write this:
Rotation matrix.
Reliable, but not efficient.
It has hundreds of lines.
Don't create your own rotation matrix unless you have to. It's much simpler to just use allegro's transform api to get your coordinates.
I think my answer is necessary.
Sorry, because Allegro's manual is not detailed.I can't understand something.
And, you know, I'm a learner.I need to accumulate experience.
And, my game will be very complicated.
The implicit operation of the Allegro.It's not good for me to think.
And, believe me, the code is in most cases only the midpoint distance measurement.
Sorry, because Allegro's manual is not detailed.I can't understand something.
Allegro's manual is actually pretty good. If you have specific questions about it, ask away.