Help with random movement

Hi all

i have started with my enemy random movement and i am kind of stuck this is what i have got, it just doesnt seem to rotate


i have also got a condition at start of scene and action reset the timer “Change Direction”

but dont know what im doing wrong if you want to try and test certain things i have attached the file
Tank Commander1.rar (1.09 MB)

sorry all it doesnt matter i just realised i missed out the trigger once conditions off the angle of enemy

There is another problem, you are testing equalities between the tank direction and an integer, it’s unlikely to happen, the tank direction is a float (I guess it rotates free, since you use the “rotate towards” action), it could be 179.976940474 while tries to rotates toward 180. You should test ranges (inequalities): Angle of tank > 175 and Angle of tank < 185 :wink:

wow thankyou i am sorting that problem now :wink:

i have just realised the tank rotates to the set amount and then it sets the variable to move enemy so it will never have a different angle other than the ones i have defined.

It can still be a problem.

if i rotate to ranges between angle 175 and 185 that will mean the enemy tank will always be at a funny angle when the tanks variable changes, i want the enemy tank to move in 4 directions, i am removing the 5th variable as it is not needed, but if my tank rotates towards angle 90 and i have a separate condition stating that once angle is 90 to move the tank using the designated variable, i dnt see how it can produce any other outcome unless someone wants to test my game to see what happens just ask and ill post the files, but from what i can see they rotate and move fine.

Sometimes a floating point value can look like 100, but it’s actually 99.999996. Floating point arithmetic is not as precise as you might think.

It’s best to avoid the chance of it happening completely. :wink:

See this for more info: stackoverflow.com/questions/1161 … sible-in-c

 Angle of tank > 179 and Angle of tank < 180. 

Maybe you won’t have a problem with how you write your code now. Maybe you will. Maybe you won’t, but a user of the game will. Or, you can just make a small range and never have a problem ever.

< 181*

dnt get me wrong i am going to change it, i just couldnt work out how it wouldnt work but if people seem to think it myt be abit buggy then better changing it nw than havning to go bk and redo it

If you want to know the reason why this can cause bugs: isocpp.org/wiki/faq/newbie#floating-point-arith

It’s a bit technical, but not terribly so.

ahhhhhh thankyou so much i understand why it can cause bugs nw and has probably helped me with other things that i will be implementing.

sorry about doubting you, i just like to know precisely why i can not do it so i know my way around abit better :stuck_out_tongue:

ok so i have now fixed that problem but it did throw a few errors into the works which i have managed to sort.

i now have it so if the tank is rotated >= 179.5 but <=180.5 to make the tank move, i was having problems when i had >=179 but <=181 because as the tank was starting to rotate it was still triggering the variable to move so i had to shorten the parameters.

Thanks everyone it is now smoother than a baby’s bum :slight_smile: