Search Unity

Bug Jerky Unity Spline movement (From Package)

Discussion in 'Editor & General Support' started by VDiablo, Mar 13, 2023.

  1. VDiablo

    VDiablo

    Joined:
    May 20, 2019
    Posts:
    4
    Hey guys,

    There seems to be some erratic SplineAnimate behaviour with certain camera angles.

    I've been implementing a racing game that utilizes Unity's SplineAnimates and SplineContainer. There are multiple cameras throughout the race of two types: LookAt, and Follow.

    The follow camera simply latches to the racer via child/parent relations or the parent constraint. For profile shots with this follow camera, you can see the SplineAnimates behind the followed racer move sporadically.

    I've updated the spline package, I've implemented my own SplineAnimate movement with the container, and I've tried the exact same SplineAnimate movement source with some modifications and the jerkiness still happens which leads me to believe there might be an issue with the PositionEvaluation from SplineContainer.

    Please refer to this uploaded video:


    In the video, I used a simple straight spline with SplineAnimates, parented the camera, and offset the movement speeds. You will clearly see the racers that fall behind start to jerk erratically. I then disable the splineAnimates and implemented an incredibly simple movement script with offsets again, and you can see there is no jerky movement.

    If anyone knows how to tackle this issue or point out mistakes from my end that would be greatly appreciated.

    Thanks,
    Martin.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    The term "erratic" makes me think maybe you're mixing Update() and FixedUpdate() for movement and camera update.

    Here is some timing diagram help:

    https://docs.unity3d.com/Manual/ExecutionOrder.html

    Here is an abbreviated and better-annotated version of the above:

    https://forum.unity.com/threads/a-c...ution-order-of-unity-event-functions.1381647/

    Two good discussions on Update() vs FixedUpdate() timing:

    https://jacksondunstan.com/articles/4824

    https://johnaustin.io/articles/2019/fix-your-unity-timestep

    You MAY also wish to get out of the camera wrangling business!! Camera stuff is pretty tricky... you may wish to consider using Cinemachine from the Unity Package Manager.

    There's even a dedicated forum: https://forum.unity.com/forums/cinemachine.136/
     
  3. VDiablo

    VDiablo

    Joined:
    May 20, 2019
    Posts:
    4

    I appreciate the effort you took to respond. Please note that in the video, I'm using Unity's "SplineAnimate" component. The jerky movement isn't handled by any of my scripts, but Unity's. I'm pointing out an issue Unity's spline package has, and I'm looking for a way to work around it or to edit the source code to work for me.

    I'm sure Unity's dev team is aware of the differences between their update loops ;)

    I've used Cinemachine, and sure it's good, but just for a follow and lookAt camera, that is very much overkill. There is no problem with my lookAt and Follow scripts, heck even Unity's "ParentConstraint" component works the exact same way as my FollowScript. Those camera mechanics are easy to handle and not the issue.
     
  4. VDiablo

    VDiablo

    Joined:
    May 20, 2019
    Posts:
    4
    In fact, I'm almost certain the issue isn't with the SplineAnimate component but with the SplineContainer, specifically its evaluation calculations the SplineAnimate utilizes.
     
  5. IMC66123

    IMC66123

    Joined:
    Mar 1, 2022
    Posts:
    1
    Hi @VDiablo
    I also have an animation issue with Splines (version 2.4.0).

    Contrarily to your issue, though, it works fine in the editor game mode for me.
    However, as soon as I export to WebGL the animation gets all jaggy and jerky.

    Writing a script myself didn't change anything. As you mentioned, SplineContainer.Evaluate seems to be broken somewhere, at least in WebGL export.

    Did you find a solution in the meantime? Did you find an alternative for splines that works?

    Thanks and cheers,
    F