2

I am trying to make a mobile game that consist on a character travelling in a 3d ambient (think about endless runner but you wont only run straight forward you can go down, up right left and have 180º curves) also instead of have only left and right moves possible mine has 9 (think about a 3x3 grid)

explaining the problem:

i Use ItweenPath

My Camera is a child of character (that means it will mimic character movement and rotation) follows the path (and look at it so if the path goes down my character AND camera will be facing downwards) normally but when he approaches/enter in a 180º curve like this -> ) <-- (up/down motion/ x Axis) at the middle of the curve he does a 180º flip (Left/right motion/ y axis) instead of just simply following the path.

why is that a problem? because at the end of that curve my charactar (and camera) should be upside down, and they are not, SO when i go to change a path for example, i want to change to the right path i need to click the LEFT arrow because the character is upside down of the correct position (got the point?)

PS: I DID a quick fix but it will apresent some problem for the future which is: at the flipping point i switched the paths with its opposite side (so when it flips all paths will be crossing) i would like to avoud that if possible

here is the code:

//info about the paths:
             iTween.Hash("path", iTweenPath.GetPath("MidPath"), "time",tempoTotal ,"orienttopath", true, "easetype", iTween.EaseType.linear );    
             iTween.Hash("path", iTweenPath.GetPath("LeftPath"), "time",tempoTotal ,"orienttopath", true, "easetype", iTween.EaseType.linear);    
             iTween.Hash("path", iTweenPath.GetPath("RightPath"), "time",tempoTotal ,"orienttopath", true,  "easetype", iTween.EaseType.linear);
             iTween.Hash("path", iTweenPath.GetPath("UpMidPath"), "time",tempoTotal ,"orienttopath", true,  "easetype", iTween.EaseType.linear);    
             iTween.Hash("path", iTweenPath.GetPath("UpLeftPath"), "time",tempoTotal ,"orienttopath", true,  "easetype", iTween.EaseType.linear);    
             iTween.Hash("path", iTweenPath.GetPath("UpRightPath"), "time",tempoTotal ,"orienttopath", true,  "easetype", iTween.EaseType.linear);
             iTween.Hash("path", iTweenPath.GetPath("DownMidPath"), "time",tempoTotal ,"orienttopath", true,  "easetype", iTween.EaseType.linear);    
             iTween.Hash("path", iTweenPath.GetPath("DownLeftPath"), "time",tempoTotal ,"orienttopath", true,  "easetype", iTween.EaseType.linear);    
             iTween.Hash("path", iTweenPath.GetPath("DownRightPath"), "time",tempoTotal ,"orienttopath", true,  "easetype", iTween.EaseType.linear);
             //Storing the position of path nodes in arrays, my character travel will be guided by those:
             pathM = iTweenPath.GetPath ("MidPath");
             pathL = iTweenPath.GetPath ("LeftPath");
             pathR = iTweenPath.GetPath ("RightPath");
             pathUM = iTweenPath.GetPath ("UpMidPath");
             pathUL = iTweenPath.GetPath ("UpLeftPath");
             pathUR = iTweenPath.GetPath ("UpRightPath");
             pathDM = iTweenPath.GetPath ("DownMidPath");
             pathDL = iTweenPath.GetPath ("DownLeftPath");
             pathDR = iTweenPath.GetPath ("DownRightPath");

//i use this to change the path..
             strPath = "mid";
             currPath = pathM;

(...)
//This is the calculation
//countTime -> time passed since start (i see the percent of path travelled by the time in sec)
//percent -> percent of path completed
//futurePercent -> used to make a prediction of the percent when i change path (the character doesnt stop moving when changing paths)
//futureRotate -> this is used to make the character face/look at the path in FRONT of him
//possible -> if the character is on the leftest path he cant go left anymore.
     countTime += Time.deltaTime; //Tempo
         percent = (countTime / tempoTotal)-0.001f;
         futurePercent =((tempoTroca+countTime) / tempoTotal)-0.001f; 
         futureRotate =(countTime / tempoTotal)+0.201f;
         possible=false;

//InputKeys to change path
//stuff -> the position of the other path that character will move to
         if (Input.GetKeyDown(KeyCode.LeftArrow)) {
             if (strPath == "right") {
                 possible = true;
                 currPath = pathM;
                 strPath = "mid";
                 stuff = iTween.PointOnPath(iTweenPath.GetPath("MidPath"), futurePercent);


//THE PROBLEM IS PROBABLY HERE
  if (move == true && countTime >= timeFixed-(tempoTroca/2)) {//this works when character changes path
          stuff = iTween.PointOnPath(currPath, futureRotate); //get the position where it will move
          iTween.LookTo (gameObject, iTween.Hash("looktarget", stuff, "time", tempoTroca/2));//looks at it
}

   if (move == false || countTime > timeFixed) {//this wont be running if the character is changing path
          move = false;
stuff = iTween.PointOnPath(currPath, futureRotate);
          iTween.LookUpdate (gameObject, iTween.Hash("axis", "x","looktarget", stuff, "time", lookTime)); //constantly looking at the path

          if (countTime <= tempoTotal)
          iTween.PutOnPath (gameObject, currPath, percent); //makes character move
     }

I ALSO think that the problem maybe in the iTweenPAth itself, refusing to be upsidedown, i say this because i did a 360º curve (a circle to be exact) in X axis and the Character does an (instant) 180º flip in Y axis

Sorry for the long text i hope someone bothers enough to help me with this struggle

  • I forgot something: I tried to lock the Y Axis from rotating BUT the object stills rotates but in other axis (x) i will try to post a video IF someone asks me to. – Fábio Empadinhas May 26 '17 at 18:04

0 Answers0