Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

iTween Question

Discussion in 'Scripting' started by aviles622, Dec 13, 2014.

  1. aviles622

    aviles622

    Joined:
    Oct 16, 2014
    Posts:
    21
    I am creating a horse racing game in Unity. I used iTween to create one complete path around the center of my race track. I am in the beginning stages of the game and have successfully moved one horse around the path from start to finish using this code: (Movement and rotation are working perfectly.)

    Code (CSharp):
    1. iTween.MoveTo(gameObject, iTween.Hash("path", iTweenPath.GetPath("1MileTrack"), "time", 20, "islocal",true, "orientToPath",true, "lookTime", 0.2, "easetype", iTween.EaseType.easeInOutSine));
    The y transform position is always at 0. (always on a flat ground)

    I plan to add a total of 10 horses to the game and my question is:

    How could I get the remaining 9 horses to follow the same path? Is there an offset value I can use in my script to offset the x transform of each horse so that each offset horse will not try to start off running towards the first node in the x position?

    Or should I create a separate path for all 10 horses in the race?
     
  2. aviles622

    aviles622

    Joined:
    Oct 16, 2014
    Posts:
    21
    Here is an image of my game so far with one horse and my path. (This path is not really symmetric or complete yet as I'm just waiting for some input as to which approach to take.) Path.png
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,683
    Mohave not used iTween in some time but I think each object would need its own tween.
     
  4. aviles622

    aviles622

    Joined:
    Oct 16, 2014
    Posts:
    21
    Thank you renman3000 which leads me to my next question.....
    Each path has 20 nodes. If I make 10 different tweens (paths) I will have a total of 200 nodes. Are these node arrays very hard on performance with iTween?
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,683
    Well, the thing with iTween is that the maker of, stopped udating the program a few years ago to concetrate on other projects. As such, its by far, not the fastest of the tween api's available. I use HOTween. It's super handy, and light on performance.
     
  6. aviles622

    aviles622

    Joined:
    Oct 16, 2014
    Posts:
    21
    Update: Actually if anyone is trying to do something similiar to this original post I got it working great with just one path in the center of my track all the around from the start line to the finish.......

    1) Create the path as above image (On center of track)
    2) Create all objects that will follow path (In my case 10 horses)
    3) Create an empty game object in the center of track at (0, 0, 0)
    4) Duplicate the empty game object 10 times. (Or as many times as you have objects you want to follow the same path)
    5) Leave all empty game objects transform position at (0, 0, 0)
    6) Attach object1 to empty game object1 (offset the actual object x position on track in the lane you want it in, not the empty game object.)
    7) Repeat step 6 for as many objects you have in the race.

    All objects will follow the same path in their own lanes!

    Now all I have to do is change speeds randomly to simulate a race.