Results 1 to 3 of 3
Thread: AI basics not working?
 04302013, 08:08 PM #1Member
 Join Date
 Apr 2013
 Posts
 41
 Rep Power
 0
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;
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;
and the seekerspeed is just a variable which is .06
 05012013, 09:46 AM #2Moderator
 Join Date
 Apr 2009
 Posts
 13,541
 Rep Power
 27
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.
** This space for rent **
 05042013, 08:44 PM #3Member
 Join Date
 Apr 2013
 Posts
 41
 Rep Power
 0
Similar Threads

java basics
By rachushetty in forum New To JavaReplies: 6Last Post: 11132012, 12:43 PM 
Help with VM and JMX Remote Basics
By Bongo Boy in forum New To JavaReplies: 0Last Post: 04282012, 09:29 PM 
Basics
By avish12 in forum SWT / JFaceReplies: 2Last Post: 06092010, 03:04 PM 
Really Basics
By Taluntain in forum New To JavaReplies: 16Last Post: 10082009, 09:43 AM 
Basics
By AKP in forum New To JavaReplies: 7Last Post: 05232008, 12:06 PM
Bookmarks