Itween paths and generating nodes won't work. please help
Hello human beings!
I am trying to use Itween Paths to "record" the position of the player in some given times and then create a cube that will run through the recorded positions.
Currently i am able to record the positions of the player and copy them to another Itween paths code on the cube but i have ran into some problems i hope you might be able to help me:
The positions of the player are being recorded only if the Game object the records them is selected in the hierarchy.
The cube won't go through the points or even move.
CODE:
Recording script:
void UpdateActions(){ //Being called every 0.25 seconds.
if (canRecord) {
if(timePassed != 0){
walkingPath.nodeCount = (int)(timePassed / recordingDistance) + 1;
walkingPath.nodes [walkingPath.nodeCount - 1] = player.transform.position;
}
timePassed += recordingDistance;
}
}
Walking script:
void Update () {
iTween.MoveTo(gameObject, iTween.Hash(
"path", iTweenPath.GetPath("myWalkingPath"),
"time", 5,
"orienttopath", true));
}
If you can help me that would be great. tx
Ethan
Answer by dhore · Aug 27, 2016 at 01:11 PM
You haven't coded the hashtable correctly. Your walking script should be like this:
iTween.MoveTo(gameObject, new Hashtable {
{ "path", iTweenPath.GetPath("myWalkingPath") },
{ "time", 5 },
{ "orienttopath", true } });
Also, since you're manually setting positions for the path you don't need to be dealing with the iTweenPath class. Instead you can just use a Vector3[]
or better yet a List<Vector3>
. This will give you full control and make sure nothing's going wrong behind the scenes out of your reach, if you get what I mean..
At first i did like what you suggested but it got super complicated really fast, plus i'm not setting the positions manually. i have a script which assigns a new position every 0.25 seconds.
I fixed it like this:
iTween.$$anonymous$$oveTo (gameObject, iTween.Hash (
"path", iTweenPath.GetPath ("myWalkingPath"),
"speed", 5f,
"easetype", "linear",
"orienttopath", true,
"axis", "y",
"onComplete", "FinishPath"));
And the recording script is:
void UpdateActions(){
if (canRecord) {
if(timePassed != 0){
walkingPath.nodeCount = (int)(timePassed / recordingDistance) + 1;
walkingPath.nodes [walkingPath.nodeCount - 1] = player.transform.position;
}
timePassed += recordingDistance;
}
}
But the positions aren't being recorded unless the game obeject which records the positions is viewed in the inspector which is another bug itself. do you know how to fix that?
Sorry, I've never used the iTweenPath class so I don't have any understanding of the functions that you're calling... nor have I used iTween.Hash
..I've always used new Hashtable
and by setting the positions manually I just meant that you're setting them yourself through code rather than iTween creating them itself dynamically.
Here's an example of what I'm talking about with Lists and such:
List<Vector3> walkingPath = new List<Vector3>();
float lastUpdateTime = 0f;
void Update()
{
if (lastUpdateTime + 0.25f < Time.time)
{
// avoid duplicates
if (walkingPath[walkingPath.Count - 1] != player.transform.position)
walkingPath.Add(player.transform.position);
lastUpdateTime = Time.time;
}
}
// call whenever you want the gameObject to start following the path
void FollowPath()
{
iTween.$$anonymous$$oveTo (gameObject, new Hashtable {
{ "path", walkingPath.ToArray() },
{ "speed", 5f },
{ "easetype", "linear" },
{ "orienttopath", true } });
}
Hashtable seems to be the same as hash but with curly brackets "{, }". Thank you any way :)
Your answer
Follow this Question
Related Questions
Gokit tween path position on different screen sizes 0 Answers
How to get external import filepath in AssetPostprocessor to auto import dependencies? 0 Answers
Having trouble loading unity 5.3.4p1 game with oculus cv1 0 Answers
IAP and Unity Cloud Build 1 Answer
SVGAssets 1.3.5 build for iOS error 0 Answers