Colision Detection/Attacking....
Author |
Message |
KeyBladeMaster
|
Posted: Tue Dec 04, 2007 12:17 am Post subject: Colision Detection/Attacking.... |
|
|
Alright, i need alot of help....
i need to know how to do colision detection.... i dont want that code that everyone has with the rectangles... it doesnt make any sence to me.... give me one with actuall pictures if possible...
and last i need to know how to make my enemy attack when we are close to each other.....
my program is kinda complicated so ill put lots of comments!
I HOPE SOMEONE CAN HELP WITH ONE OF THESE PROBLEMS...
Description: |
|
Download |
Filename: |
KH Game.rar |
Filesize: |
8.54 MB |
Downloaded: |
77 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
KeyBladeMaster
|
Posted: Tue Dec 04, 2007 2:15 pm Post subject: RE:Colision Detection/Attacking.... |
|
|
iight i fixed transparent color.... id dint no u had to do it before u draw the pic
|
|
|
|
|
|
Ultrahex
|
Posted: Tue Dec 04, 2007 2:53 pm Post subject: Re: Colision Detection/Attacking.... |
|
|
I am assuming you are doing rectangle-rectangle collision, if not you need to state your question more clearly.
For Rectangles/Squares to overlap/collide, they must have one of their points in the other rectangle, that is:
so from the diagram, they have to share the same space in order for a collision to occur, and one of the rectangles vertex/points has to be inside the others.
thus, you can use analytical geometry and prove when they are colliding, however, if you have not learned this...
there is easier ways, the real question in rectangle-rectangle collision, is when are they NOT colliding.
Well that is when the x-coordinate and y-coordinate are out of the range.
Horizontal Check
(X-axis check) ... Determines if they are NOT overlapping horizontally.
(x1 > x2+w) - the left side of the first rectangle is greater then the right side of the second rectangle. (that is the first rect is to right of the second rect)
(x1+w < x2) - the right side of the first rectangle is less then the left side of the second rectangle. (that is the first rect is to the left of the second rect)
Vertical Check
(Y-axis check) ... Determines if they are NOT overlapping vertically.
(y1+h < y2) - the bottom of the first rectangle is less then the top of the second rectangle (the first rect is above the second rect)
(y1 > y2+h) - the top of the first rectangle is greater then the top of the second rectangle (the first rect is below the second rect)
notes
note if i remember correctly about Turing Graphics, this approach needs modified to your system because you do not know the width and height of your objects you just know your two corners, can easily be adapted however.
|
|
|
|
|
|
Clayton
|
Posted: Tue Dec 04, 2007 5:09 pm Post subject: RE:Colision Detection/Attacking.... |
|
|
You can use Pic.Width() and Pic.Height to find the width and height of a picture.
|
|
|
|
|
|
StealthArcher
|
Posted: Tue Dec 04, 2007 6:13 pm Post subject: RE:Colision Detection/Attacking.... |
|
|
http://compsci.ca/v3/viewtopic.php?t=14552
Here's code for a game I made once, read it to find how I did rectangle collision, oh and it has pictures .
|
|
|
|
|
|
KeyBladeMaster
|
Posted: Tue Dec 04, 2007 9:46 pm Post subject: RE:Colision Detection/Attacking.... |
|
|
i need more help..... i have a menu now, and music... i have different music for the menu and different music for my first level... they are both in different forks and when i start game no music starts....but like when im about to exit and it asks if im sure thats when the music starts....:S:S:S
|
|
|
|
|
|
rcbhs
|
Posted: Wed Dec 05, 2007 9:38 am Post subject: Re: Colision Detection/Attacking.... |
|
|
if my coordinates are variables because both object are constantly moving, how do I get the collision for all sides? My variables are manx, many, ghostx, ghosty for the 2 objects I need to collide. What I have now is totaly screwed and works quite strangely.
if (manx <= ghostX + Pic.Width (ghostID)) and
(many >= ghostY - Pic.Height (manID)) and
(many <= ghostY + Pic.Height (ghostID)) then
put "collision"
end if
is the code i currently have for the collision and my collision is weird (I'll try to draw it out here)
------------------------------------------------------------------
---------------------------------------------------------lGHOSTl
------------------------------------------------------------------
Now with what I have, whenever my man goes into that box in any way it sees collision, instead of just colliding with the ghost box.
Any help at all as to how I can fix my collision so it works properly would be great. (the explination above didn't help much) I tried getting it to work based on what was said earlier but I failed horribly.
|
|
|
|
|
|
|
|