Right, i have three varibles ...
After a little bit of code, i have worked out this varibles value...
What i want to do is add the speed to the current direction (or subtract, depending on iTurnDir) to make it reach the wanted direction.
Now my question is, does anyone have a efficent and elegent solution to limit the current direction to the wanted direction with out over stepping it?
Say for example, the solution needs to be able to deal with;
1. speed=10 current=10 wanted=200 iTurnDir=1 <- current will = 20
2. speed=100 current=300 wanted=10 iTurnDir=1 <- current will = wanted
3. speed=100 current=10 wanted=300 iTurnDir=-1 <- current will = wanted
Now lets see what you lot can come up with :)
Speed:Float 'Speed to change directions at (could be anything) Current:Float 'Current direction (0 to 360) Wanted:Float 'Wanted direction (0 to 360)
After a little bit of code, i have worked out this varibles value...
iTurnDir:Int '=-1 anti-clockwise, 0 = no turn needed, 1 = clockwise
What i want to do is add the speed to the current direction (or subtract, depending on iTurnDir) to make it reach the wanted direction.
Now my question is, does anyone have a efficent and elegent solution to limit the current direction to the wanted direction with out over stepping it?
Say for example, the solution needs to be able to deal with;
1. speed=10 current=10 wanted=200 iTurnDir=1 <- current will = 20
2. speed=100 current=300 wanted=10 iTurnDir=1 <- current will = wanted
3. speed=100 current=10 wanted=300 iTurnDir=-1 <- current will = wanted
Now lets see what you lot can come up with :)