Advertisement

Character movement and side position..

Started by August 17, 2000 12:22 AM
2 comments, last by HellRiZZer 24 years, 3 months ago
OK, here is a question: I got a character, he can be turned onto 8 sides : NE N NW E W SE S SW or 1 2 3 8 4 7 6 5 how i could implement the turning algorithm from all positions to any and it must be a shortest one? like i want to turn from NW to E and it must go NW,N,NE,E, not N,NW,W,SW,S,SE,E.
Try This....

    enum LeftOrRight {LEFT, STAY, RIGHT};LeftOrRight FindDirection(int Desired, int Current){int index_dif = 0; //used to count how many indexes cycled thruif(Current == Desired)  //don''t need to turn... return STAY;int tempCur = Current; //save the Current direction (if needed)//Do until you reach the desired direction (or return early)  while(tempCur != Desired)  {   index_dif++; //count this direction   tempCur++;   //inc your direction   if(tempCur > 7)  //restart at beginning of directions	 tempCur = 0;   if(index_dif > 4)  //you know that the OTHER way is now best      return LEFT;       }   return RIGHT;}     



You may have to switch around the RIGHT and LEFT returns, depending on which way you have your directions set up.

Also, this is probably not the MOST optimized function in the world. But, if you do it right, you would only need to call this once (just find the direction you need to turn, then just keep turning until you get to the desired direction)

Hope it works for you. If you have any questions, let me know.

Mihkael
Advertisement
How about this code(designed today..)

val(text1.text) is a start point
val(text2.text) is a end point

text3.text is a result - AntiClockWise or ClockWise
If Val(Text1.Text) > Val(Text2.Text) Then
If Val(Text1.Text) - Val(Text2.Text) > 4 Then
Text3.Text = "Clock"
Else
Text3.Text = "Anti"
End If
End If
If Val(Text1.Text) < Val(Text2.Text) Then
If Val(Text2.Text) - Val(Text1.Text) > 4 Then
Text3.Text = "Anti"
Else
Text3.Text = "Clock"
End If
End If
Thanks ANYWAY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Cyas later.. Your way I tried, it works! THANKS!

This topic is closed to new replies.

Advertisement