1. Member
Join Date
Apr 2013
Posts
41
Rep Power
0

## Combat collision AI

Hi so I am new to programming like AI and was curious as to how to calculate if it has collided with something, hmm ill go into more detail. so when the user presses the space key a circle generates around his character.(the size is 50x, 50y). I want to know if the AI is within that circles radius. I have never done anything like this before so im alittle confused lol. At first i thought this would work:
Java Code:
```if(((birdx + aw[0] > knightPositionX)||(birdx - aw[0] < knightPositionX)) && ((birdy + ah[0] > knightPositionY)||(birdy - ah[0] < knightPositionY))){
seekerchp[s] = seekerchp[s] - knightd;
drawbird = true;
}```
note the aw[0] is just area wide and ah is area height. both represent 50.
Clearly after i tested it i looked over it and *falmpalm* that is an awful peice of code...

Any ideas? im not asking for you to make it for me, just alittle push in the right direction.

oh also i dont know if its possible to use the:
Java Code:
`g.drawOval(knightPositionX -5, knightPositionY -5, aw[0], ah[0]);`
to make this collision detection any easier?
Thankyou.

2. Moderator
Join Date
Apr 2009
Posts
11,302
Rep Power
18

## Re: Combat collision AI

1. You know the location of the character.
2. You know the location of the AI.
3. You know the radius of the circle.

So using 1 and 2 you can calculate the distance between the character and the AI.
If that is less than the value of 3 then the AI is within the circle.

3. Member
Join Date
Apr 2013
Posts
41
Rep Power
0

## Re: Combat collision AI

Originally Posted by Tolls
1. You know the location of the character.
2. You know the location of the AI.
3. You know the radius of the circle.

So using 1 and 2 you can calculate the distance between the character and the AI.
If that is less than the value of 3 then the AI is within the circle.
I clearly wasnt in the right state of mind last night.. fixed it thank you!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•