2

我正在尝试制作一个包含在3d 环境中旅行的角色的手机游戏(想想无尽的跑步者,但你不会只向前奔跑,你可以向下、向右上方并有 180º 曲线),而不是只有左和正确的移动可能我的有 9 个(考虑一个3x3 网格

解释问题:

我使用ItweenPath

我的相机是角色的孩子(这意味着它将模仿角色的移动和旋转)跟随路径(并看着它,如果路径向下,我的角色和相机将朝下)通常但是当他接近/进入时像这样的180º 曲线-> ) <-- (上/下运动/ x轴)在曲线的中间,他做了 180º 翻转(左/右运动/ y轴),而不是简单地跟随路径。

为什么这是个问题?因为在该曲线的末端,我的角色(和相机)应该是倒置的,而它们不是,所以当我去更改路径时,例如,我想更改正确的路径,我需要单击向左箭头,因为角色颠倒了正确的位置(明白了吗?)

PS:我做了一个快速修复,但它会给未来带来一些问题,那就是:在翻转点,我用它的另一侧切换了路径(所以当它翻转时,所有路径都会交叉)我想避免如果可能的话

这是代码:

//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
     }

我还认为问题可能出在 iTweenPAth 本身,拒绝倒置,我这么说是因为我在 X 轴上做了一个 360º 曲线(准确地说是一个圆),而角色在 Y 轴上做了一个(即时)180º 翻转

很抱歉,我希望有人费心帮助我解决这个问题

4

0 回答 0