- Home /
Itween 180º curve position and rotation problem
I am trying to create a simple mobile game where my character is following a certain path (using ItweenPath) there is a point in the path where he have a 180º curve, so it should end up upside down (the camera is a child of the character so it will do everything exactly the same) BUT the itweenPath is making the character rotate 180º on Y axis that is a problem for me because if he does that, the right and left arrow keys are now, respectively, left and right i will past some code
Character has 9 paths in a 3x3 grid style where he can change between them to avoid objects or to pick up some
void Start () {
//Adicionar propriedades aos caminhos
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);
//Caminhos em array
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");
strPath = "mid";
currPath = pathM;
}//fim do Start
I use PutOnPath + LookUpdate to move and rotate/point the object into the path so the player knows where he is going i didnt used MoveTo because i cant change between paths with MoveTo (or atleast i dont know how)
countTime += Time.deltaTime; //Tempo
percent = (countTime / tempoTotal)-0.001f;
futurePercent =((tempoTroca+countTime) / tempoTotal)-0.001f;
futureRotate =(countTime / tempoTotal)+0.201f;
possible=false;
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
if (strPath == "right") {
possible = true;
currPath = pathM;
strPath = "mid";
stuff = iTween.PointOnPath(iTweenPath.GetPath("MidPath"), futurePercent);
}
$$anonymous$$ore info: so far test didn't helped my solving but new info here: i am going to past the code where i think the problem is:
if (move == true && countTime >= timeFixed-(tempoTroca/2)) {
stuff = iTween.PointOnPath(currPath, futureRotate);
iTween.LookTo (gameObject, iTween.Hash("looktarget", stuff, "time", tempoTroca/2));
}
if (move == false || countTime > timeFixed) {
move = false;
iTween.LookUpdate (gameObject, iTween.Hash("axis", "x","looktarget", stuff, "time", lookTime));
if (countTime <= tempoTotal)
iTween.PutOnPath (gameObject, currPath, percent);
stuff = iTween.PointOnPath(currPath, futureRotate);
}
The problem is probably on: "iTween.LookTo" or "iTweenLookUpdate" when i disable the rotation in the on LookUpdate he stops rotating BUT the camera rotates ins$$anonymous$$d so i am no longer looking forward
some explanation code: the first if its when i change paths i look to the target path, the second if is to look forward the current path
ANOTHER strange thing for me: if i put ("axis", "y") the Y will still rotate but X wont, and if i put "Z" it wont rotate on any axis, if i put X it wont rotate on X and Y, that is rather confusing for me ..
I did a quick fix WHICH is not Optimal but basicly since when teh object turns aroudn 180º making the right/left and Up/Down paths be Opposite i switched the last 2 node (before teh problem appearing) to the opposite sides so now in last 2 nodes the right path is named left etc .. (i hope you get) something strange about that is: The Y Rotation happens EXACTLY on the Crossing of paths o i am thinking that maybe the ITweenPath (the visual) its rotation (by itself since i dont have or dont know how to rotate ItweenPath script on visual editor) i am to leave for today i hope someone comes up with some ideas or test for me to try out