0

ok i using libgdx for android game development and i have a AI which moves depending on value of variable "ENEMYSPEED". Initally the value is set as

static float EnemySPEED = 0.5f;

and everything works fine. so i perform a simply compute like this

EnemyVector.y -= EnemySPEED

Everything fine so far...

Now i feel my AI is moving fast and i decrease the variable value from 0.5f to 0.4f and i perform the same operation of decrement and it doesn't decrement!

What is going on??!!!

EDIT:

private void EnemyMove()
{
    EnemySection = findSection(Enemy);
    if(EnemySection == PlayerSection)
    {
        if(EnemyVector.x > PlayerVector.x) EnemyVector.x -= EnemySPEED;
        else if(EnemyVector.x < PlayerVector.x) EnemyVector.x += EnemySPEED;        
        else if(EnemyVector.y > PlayerVector.y) EnemyVector.y -= EnemySPEED;
        else if(EnemyVector.y < PlayerVector.y) EnemyVector.y += EnemySPEED;
    }
    else if(EnemySection == 1 ||EnemySection ==  3) EnemyVector.x += EnemySPEED;
    else if(EnemySection == 2 ||EnemySection ==  4) EnemyVector.x -= EnemySPEED;
    else if(EnemySection == 5)
    {
        if(EnemyVector.y > 212 || EnemyVector.y < 75)
        {
            if(PlayerSection == 1 ||PlayerSection ==  3) EnemyVector.x -= EnemySPEED;
            else if(PlayerSection == 2 ||PlayerSection ==  4) EnemyVector.x += EnemySPEED;  
        }
        else
        {
            if(PlayerSection == 1 ||PlayerSection ==  2) EnemyVector.y += EnemySPEED;
            else if(PlayerSection == 3 ||PlayerSection ==  4) EnemyVector.y -= EnemySPEED;
        }
    }

    if(Player.overlaps(Enemy)) System.out.println("Target Acquired!");  
    System.out.println(EnemyVector.x + "," + EnemyVector.y);
}

findSection finds in which quadrant the Enemy or player is in depending on parameter passed.

EDIT 2: i just noticed that it only works for 0.5,1,1.5 not any value in between. Is this some kind of limitation?

9
  • Please provide more contextual code. The above contains no errors. Commented Feb 23, 2014 at 7:55
  • I'm confused. Your "Everything is fine so far" and the change you make don't seem to make sense. If it's fine up until you perform the operation, it seems like you're saying -= increases the speed. But then why is everything fine? You also "feel", but is it actual? Commented Feb 23, 2014 at 7:56
  • IOW, feeling like it's faster is different than debugging the code and knowing it's faster. Debugging it, BTW, should clue you in on the happenings; no? Commented Feb 23, 2014 at 7:59
  • by faster literally what i meant is how much X's in XY co-ordinate it moves Commented Feb 23, 2014 at 8:00
  • This is basically my whole AI code is Commented Feb 23, 2014 at 8:01

2 Answers 2

1

Guys i am sorry the problem was with comparing two floats... :/

for example comparing 127.8 and 127.0 is obviously wont work.

i changed the code to this and it worked fine... don't know how i missed this.. lesson learned

Anyways thank you friends for your help..

if((int)EnemyVector.x > (int)PlayerVector.x) EnemyVector.x -= EnemySPEED;
        else if((int)EnemyVector.x < (int)PlayerVector.x) EnemyVector.x += EnemySPEED;      
        else if((int)EnemyVector.y > (int)PlayerVector.y) EnemyVector.y -= EnemySPEED;
        else if((int)EnemyVector.y < (int)PlayerVector.y) EnemyVector.y += EnemySPEED;
Sign up to request clarification or add additional context in comments.

1 Comment

Please mark your own answer as 'correct' so others will know you don't need an answer anymore.
0

Try and make the EnemySPEED as volatile. It might be the case that EnemySPEED is getting cached by the thread which is executing this code, and hence you are unable to see the difference when you change the EnemySPEED from 0.5 to 0.4.

3 Comments

but EnemySPEED is not changed dynamically.. from beginning to the end of the game it doesn't change.
I thought that when you said that you decrease the variable value from 0.5 to 0.4, it meant dynamic decrement. :D
not i am sorry if i wasn't clear i just change the value and rebuild the project again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.