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

    Default AI basics not working?

    Okay so i am just baffled why this isnt 100% working...

    Java Code:
    			if(fx < ipallyx)fx += delta * .05;
    			if(fx > ipallyx)fx -= delta * .05;
    			if(fy > ipallyy)fy -= delta * .05;
    			if(fy < ipallyy)fy += delta * .05;
    			
    			if(fx2 < iknightx)fx2 += delta * .05;
    			if(fx2 > iknightx)fx2 -= delta * .05;
    			if(fy2 > iknighty)fy2 -= delta * .05;
    			if(fy2 < iknighty)fy2 += delta * .05;
    on both of the occasions where it is fx -=, fy -=, fx2 -= and fy2 -= ; they work.
    so easy to say the AI will go only negative x and y, but it wont go positive?

    I tried putting a system.out.print in the += ones and what do you know it printed; so i know that if statement is working, but for some reason theyre not moving +x or y..
    now another weird thing is that this is simply a copied movement i already made but with different variables; cause this works 100%:
    Java Code:
    			if(ibirdx < ipallyx)birdx += delta * seekerspeed;
    			if(ibirdx > ipallyx)birdx -= delta * seekerspeed;
    			if(ibirdy > ipallyy)birdy -= delta * seekerspeed;
    			if(ibirdy < ipallyy)birdy += delta * seekerspeed;
    does anyone have any ideas? cause im just confused..
    and the seekerspeed is just a variable which is .06

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,439
    Rep Power
    18

    Default Re: AI basics not working?

    OK, going to hazard a guess here as you haven't told us what type 'fx' etc are, but I'm assuming they're ints.

    Since the right hand side of the calculation is a double, I'm also guessing that 'delta * 0.05' is less than 1 each time, this is being turned into an int.
    When that happens the fraction element is remove.
    So for the subtraction we have, eg, 10 - 0.1 = 9.9...remove the fraction gives us 9.
    For addition we have 10 + 0.1 = 10.1...remove the fraction takes us back to 10.

    So if you want to work with fractions than make all the variables double/float, then convert them when you use them, assuming they need to be ints at some point.
    Please do not ask for code as refusal often offends.

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

    Default Re: AI basics not working?

    Quote Originally Posted by Tolls View Post
    OK, going to hazard a guess here as you haven't told us what type 'fx' etc are, but I'm assuming they're ints.

    Since the right hand side of the calculation is a double, I'm also guessing that 'delta * 0.05' is less than 1 each time, this is being turned into an int.
    When that happens the fraction element is remove.
    So for the subtraction we have, eg, 10 - 0.1 = 9.9...remove the fraction gives us 9.
    For addition we have 10 + 0.1 = 10.1...remove the fraction takes us back to 10.

    So if you want to work with fractions than make all the variables double/float, then convert them when you use them, assuming they need to be ints at some point.
    ahh thank you very much; converted them to floats and it worked!

Similar Threads

  1. java basics
    By rachushetty in forum New To Java
    Replies: 6
    Last Post: 11-13-2012, 12:43 PM
  2. Help with VM and JMX Remote Basics
    By Bongo Boy in forum New To Java
    Replies: 0
    Last Post: 04-28-2012, 09:29 PM
  3. Basics
    By avish12 in forum SWT / JFace
    Replies: 2
    Last Post: 06-09-2010, 03:04 PM
  4. Really Basics
    By Taluntain in forum New To Java
    Replies: 16
    Last Post: 10-08-2009, 09:43 AM
  5. Basics
    By AKP in forum New To Java
    Replies: 7
    Last Post: 05-23-2008, 12:06 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
  •