Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Following path with varying speed and quaternion interpolation

Discussion in 'Scripting' started by tib, Apr 17, 2015.

  1. tib

    tib

    Joined:
    Aug 28, 2013
    Posts:
    3
    Hello everybody,

    I'm Tib, a hobbyist game developper trying to make my 3d shmup :)

    I hope this question has not been answered yet.. I'm struggling with this problem since some days...

    I want my enemies to come from predefined 3D paths and I'm looking for the best way to do it.

    They may come back and forth from places that are not in the action 2d plane. Like in this video (at the 9-10 th second for example):


    So my path object would be made of transforms, so that the enemy position would follow smoothly (catmull rom or hermite) path nodes positions and enemy rotations would follow smoothly nodes orientations (squad maybe).

    Here are the solutions that I see:

    - using a tweening system
    I tried Hotween for example, which is very nice but I think it can only interpolate positions. For orientations interpolation, I think I should write my own plugin or use callbacks. Looks complicated...

    - using unify spline interpolator (http://wiki.unity3d.com/index.php?title=Hermite_Spline_Controller)

    I looked at the code, and it does quaternion interpolation by using squad which I think is what I need.

    But I'm afraid that if I have too many enemies (maybe 50) following the path it would be too heavy for the cpu (not sure about it).
    That's why, I'm think of this third idea:

    - making the path animation in blender and baking it. It looks feasible but the problem, is that I don't know how to do it :)


    I would be very interested in having your expert advice about these ideas and other ideas!

    PS: sorry for my bad english, I'm french

    Thank you!

    Tib
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,514
    So I personally wrote my own tween engine, as well as a path system, for this very thing.

    Of course, many tween engines already exist. Like Hotween, Dotween, and itween. But they don't have the waypoint path stuff with a nice gui with them.

    Mine isn't ready to share yet (I want to add more features to it first).

    BUT, I do know of one that I've used. There's certain things I don't like about it (hence why I wrote my own), but I've used it, and it gets the job done. It also comes with built in support for iTween and HOtween:

    http://www.rebound-games.com/?page_id=39
     
  3. tib

    tib

    Joined:
    Aug 28, 2013
    Posts:
    3
    Thanks for the answer. I think I will look into the plugin you used. Does it handle smooth interpolation of waypoints orientations too?

    As for this plugin or making my own plugin, do you think it would be overkill on CPU to have maybe 50-100 objects following a path at the same time. Should I bake the paths to spare the CPU time used to compute interpolations?
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,514
    If I remember correctly, the plugin I linked precalcs quite a bit at load time to speed up interpolation.

    I know in mine that I wrote, I also pre-calc quite a bit for the cardinal (catmull rom) splines. The timing issue to keep a constant speed across them is a bit costly, so you have to pre-calc that stuff or suffer a lot.

    I never used that plugin as heavily as I have my own, but under the hood the actual algorithm is similarish (it's catmull rom, and bezier, the algorithm is pretty standard). I can handle TONS of stuff on screen at a time. Our game has a demand for 100's of enemies running around and pathing on screen.
     
  5. tib

    tib

    Joined:
    Aug 28, 2013
    Posts:
    3
    Thank you for your help!

    For now, I will look into doing my own system and see how it goes.