Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2013
    Posts
    41
    Rep Power
    0

    Default 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. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: Combat collision AI

    Quote Originally Posted by Tolls View Post
    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!

Similar Threads

  1. ImageView Collision
    By TP-Oreilly in forum Android
    Replies: 1
    Last Post: 01-30-2012, 02:17 AM
  2. Collision
    By PhQ in forum New To Java
    Replies: 5
    Last Post: 12-12-2011, 02:20 AM
  3. [CodeFest] Virtual Combat : An extension of educational game
    By codefest11 in forum Reviews / Advertising
    Replies: 0
    Last Post: 02-10-2011, 07:52 PM
  4. Collision
    By shadycharacter in forum New To Java
    Replies: 0
    Last Post: 04-13-2010, 09:58 PM

Posting Permissions

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