Search Unity

[RELEASED] Curvy: Fast Spline Interpolation

Discussion in 'Assets and Asset Store' started by Jake-L, Feb 14, 2013.

?

Is it fine to release Curvy as a Unity 4.2 package?

Poll closed Dec 27, 2014.
  1. YES, I'm already using Unity 4

    103 vote(s)
    88.0%
  2. YES, but it should work in Unity 3.5 nevertheless

    7 vote(s)
    6.0%
  3. NO, I don't have Unity 4 installed and won't be able to access it in the AssetStore

    7 vote(s)
    6.0%
Thread Status:
Not open for further replies.
  1. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Hey, is there a way in Curvy to make a 2d spline (presuming so, a line that is just extruded in X-Y space) ... which then has 2d physics colliders on it rather than the 3d physics? Is that built in or no? Also is it easy to get a spline to regenerate the mesh every frame at runtime, including colliders?
     
  2. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    If you keep the Control Points on a plane (SceneView's 2D mode makes that very easy), the spline will be 2D only. Collider handling isn't builtin yet.
     
  3. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    It'd be really great if all the Playmaker actions bugs and the undo problems would be fixed. Thanks :)
     
  4. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Would it be possible to get an example of how to do a follow spline that plays nicely with a rigidbody? I'm trying to do it by setting the velocity to the delta, but it's not quite working.
     
  5. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Did you try setting the rigidbody to kinematic mode? Another method would be to drag the body continuously to the current spline position.
     
  6. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Got it - a seperate game object acts as the "train". The diff between the train and rigid body is added as a force to the rigidbody. When the rigidbody is more than a certain distance from the train, the train stops until it gets close enough. It's convincing enough.
     
  7. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    When will Curvy work with PlayMaker (without me having to fix every single instance I am opening)?
     
  8. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Now
     
    Fritsl likes this.
  9. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    How? It does not appear to be the case..
     
  10. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Please download pmCurvy0.25 again, missed two legacy actions...
     
  11. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    Hmm I get this error:

    Assets/PlayMaker Curvy/CurvyFollowSpline.cs(8,7): error CS0246: The type or namespace name `FluffyUnderware' could not be found. Are you missing a using directive or an assembly reference?
     
  12. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    You have the main Curvy package in your project, don't you?
     
  13. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    Hmm, just to follow up: Since updates for Curvy sometimes takes very long, it has left several projects in several versions - and this takes some time to clean up when the updates arrive - which was something causing the Error message. Gone now after all is updated manually.
     
  14. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Hey @Jake L. , I"m after a plug in that will allow me to author 2 splines and then at run time, be able to blend an object between these two splines . Is that possible with this plug in?
    Thanks
    Ant
     
  15. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    This is possible, but you'll need to write a custom controller that handles this. With a little C# knowledge this is a piece of cake. Using Playmaker you can take the positions from two splines and blend them with existing PlayMaker math actions without the need to write a custom script.
     
  16. Asier14

    Asier14

    Joined:
    Apr 7, 2013
    Posts:
    1
    Hi, i bought Curvy yesterday and its looks fine but and i want to know if is posible to inport splines from blendrer.
    Thanks.
     
  17. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Unfortunately not (yet).
     
  18. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    I'm using the SplineWalkerCon. What is the best way to get a running update of current control point.

    Edit: Did an experiment using basic SplineWalker and added the following in doUpdate() :
    var segment = Spline.TFToSegment(mTF);
    controlPt = segment.ControlPointIndex;

    Only thing is this code doesn't work for the end point.
    For example:
    Open Spline with 0,1,2,3 I get 0,1,2 instead of 0,1,2,3
    Closed spline 0,1,2,3 I get 0,1,2,3 instead of 0,1,2,3,0
     
    Last edited: Oct 1, 2014
  19. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Each segment is a CP, but not vice versa. If you have a open Spline with 4 Control Points (0,1,2,3), the last CP isn't a segment because it's the end CP. If you close the spline, CP3 becomes a segment, because it "leads to" CP0. On top of that, if you disable "AutoEndCP", you'll have additional CP's at the start and end that aren't segments.
     
  20. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Thanks for the explanation.
    What do you suggest as a good way to get the correct CP index.

    Reason is that I am trying to integrate Curvy with Behavior Designer AI. In this use case, knowing which control point the character is currently at is very important.

    I've been using SWS (simple waypoint system) but have turned to Curvy for this task because Curvy offers much more flexibility in terms of path variations. On the other hand, SWS's control-point centric paradigm makes it easy and intuitive to move the character according to the CP index. For example, move character to CP 5 or ping pong character from CP 4- CP5.
     
    Last edited: Oct 1, 2014
  21. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    There's an additional version of Spline.TFToSegment(), returning you the local F (within the segment). In your example, if you get a CPIdx==2 and localF==1, you know you're at the last CP (i.e. at the end of the last segment).
     
  22. Deleted User

    Deleted User

    Guest

    Hi,

    Wanted to say the tool is create and is working very well so far. I have run into an issue, how do I know when an object has finished following a path? Is there an event or a flag that will tell me the object has finished following the path (I am using Clamp for the Clamping mode).

    Cheers
     
  23. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    There will be events for that in following versions. Right now the usual approach is to use PingPong-Clamping. Then, if the direction sign has changed after a move, an end was reached.
     
  24. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    Hi! I just love Curvy, it's the best asset I bought so far.

    Trying to push its limits, I wanted to try to animate the "To TF" property of a Spline Path Mesh Builder component using the legacy animation system, to make it build the mesh in realtime. However, it doesn't seem to update itself dynamically when I play the animation. I understand if this is not possible to do, but would just like to check so that I'm not doing something wrong.
     
  25. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Did you set the Meshbuilder to Auto-Update?
     
  26. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    Yes, Auto Refresh is checked and Auto Refresh Speed is at 0 (tried some different values). It doesn't seem to be only To TF, but other fields as well such as From TF and Shape Width as well.

    It's a bit strange because although the Inspector fields I animate get marked with red, indicating that they are being animated, they don't change value, even though the sequencer shows that the values change when I play the animation. Other animations work, such as animating Transform.position or enabling/disabling the script through animation. Might be a Unity bug in the legacy animation system, unless the script somehow reset or lock its values every Update().

    I had no expectations that such features would be available, so this is just a bonus. I think I'll try to animate it manually through a script instead and see how it goes.
     
  27. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    I managed to animate ToTF and FromTF through a script instead. Here's the script if anyone is interested (use freely). It could be better but works for simple stuff and performs quite well, even on mobile (Samsung S3). Curvy is awesome.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using FluffyUnderware.Curvy;
    4.  
    5. // Animates a ToTF or FromTF property of a Curvy SplinePathMeshBuilder component.
    6. // Can set a start position, but not end position (always ends at 1 TF). Cannot yet animate backwards.
    7. // Use "Fast Interpolation" in SplinePathMeshBuilder for better performance and avoid animating very big meshes.
    8. public class CurvyAnimateExtrude : MonoBehaviour {
    9.  
    10.     // Public vars
    11.     public enum propertyType { ToTF, FromTF };
    12.     public propertyType propertyToAnimate; // Which property should be animnated.
    13.  
    14.     public SplinePathMeshBuilder splinePathMeshBuilder; // Which SplinePathMeshBuilder to use.
    15.     public float speed = 10f; // Speed of animation.
    16.     public float startPosition = 0f; // Optional start position in distance, not TF.
    17.  
    18.     public enum refreshType { Default, AtFinish }; // "Default" means it's based on the checkbox "Refresh Mesh Collider" in the Spline Path Mesh Builder component.
    19.     public refreshType refreshMeshCollider; // If MeshCollider should be refreshed.
    20.  
    21.     // Private vars
    22.     private float distance = 0f;
    23.     private bool isMeshColliderBuilt = false;
    24.  
    25.     void Start () {
    26.         distance = startPosition;
    27.  
    28.         if (propertyToAnimate == propertyType.ToTF)
    29.             splinePathMeshBuilder.ToTF = 0;
    30.         else
    31.             splinePathMeshBuilder.FromTF = 0;
    32.     }
    33.  
    34.     void LateUpdate()
    35.     {
    36.         // Only update if end has not been reached
    37.         if ((propertyToAnimate == propertyType.ToTF && splinePathMeshBuilder.ToTF < 1f) || (propertyToAnimate == propertyType.FromTF && splinePathMeshBuilder.FromTF < 1f)) {
    38.  
    39.             // We use distance instead of TF to get an even animation even if segments are of different lengths.
    40.             distance += speed * Time.deltaTime;
    41.  
    42.             if (propertyToAnimate == propertyType.ToTF)
    43.                 splinePathMeshBuilder.ToTF = splinePathMeshBuilder.Spline.DistanceToTF(distance);
    44.             else
    45.                 splinePathMeshBuilder.FromTF = splinePathMeshBuilder.Spline.DistanceToTF(distance);
    46.  
    47.             splinePathMeshBuilder.Refresh();
    48.         }
    49.  
    50.         // If we want to refresh MeshCollider at finish
    51.         if (refreshMeshCollider == refreshType.AtFinish && !isMeshColliderBuilt) {
    52.             if (propertyToAnimate == propertyType.ToTF && splinePathMeshBuilder.ToTF >= 1f)
    53.                 RefreshMeshCollider ();
    54.             else if (propertyToAnimate == propertyType.FromTF && splinePathMeshBuilder.FromTF >= 1f)
    55.                 RefreshMeshCollider ();
    56.         }
    57.      
    58.     }
    59.  
    60.     void RefreshMeshCollider() {
    61.         if (!isMeshColliderBuilt) {
    62.             splinePathMeshBuilder.RefreshMeshCollider = true;
    63.             splinePathMeshBuilder.Refresh ();
    64.             splinePathMeshBuilder.RefreshMeshCollider = false;
    65.             isMeshColliderBuilt = true;
    66.         }
    67.     }
    68. }
    69.  
    A more flexible solution would be to use a FollowSpline component to dictate the animation.
     
    Last edited: Oct 21, 2014
  28. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Hi Jake,

    I have a close bezier path and using CurvyClonePath to populate the path with small spheres.

    Question: How can I make each sphere to follow the spline? Currently, I have a Follow Spline script on each of the sphere but instead of each sphere being evenly distributed along the path, all the cloned spheres are placed at the same position as the original sphere? There is some small thing I'm missing to get this working.

    Edit: Essentially, after being cloned and positioned on the spline, the follow Spline script should use each sphere's current position as the starting point.

    Cheers.
     
    Last edited: Oct 27, 2014
  29. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    Hello,
    I would like to use curvy to animate an Oculuis Rift camera and to animate a platform. Some questions before I buy...
    - Can this be done without camera vibration? thats usually the issue with other spline systems.
    - can I trigger the path and fly to the start point for a smooth start to my path, then drop the player off at another point to resume walking?
    - does Curvy support ease in/outs?
    - does it support camera lock to spline but headtracking allowed?

    thanks!
     
  30. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Hi,

    I didn't noticed camera vibrations yet, but if they occur their are related to float inaccuracy rather than Curvy. Easing isn't supported natively, but you can create a custom controller and manipulate the movement speed using one of the easing plugins floating around. Movement without orientation change is possible.

    About the 2nd question: can you give more details, I'm not 100% sure what you want to do...
     
  31. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    I would like to trigger the path animation of my camera & player using a playmaker trigger, anyway along the trigger's length. At that point a maove to path would float me to the 1st path point and start the path animation.

    The vibration only happens when I try to attach a UFPS player controller to a spline in a different spline asset.
    I assume its the player's rigibody/physics...

     
  32. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    When your trigger executes, you'll need to move your player "manually" to the start of the spline (the position can be get easily), then start moving the spline with another action.
     
  33. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    cool thanks
     
  34. ChaneDev

    ChaneDev

    Joined:
    Feb 12, 2013
    Posts:
    66
    I feel like I am missing something obvious.

    I basically want an object to start and follow to the end of the whole spline at a specific speed. I've tried each of the PlayMaker Actions, but adjusting the speed variable causes the object to only reach specific points along the spline or reach of the end of the speed is greater than X value. Any ideas what I am missing?

    Unity 4.5.5f1
    Curvy 1.61f

    Thanks,
    ~C - - -
     
  35. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Hi Jake,

    I just picked this up and think it is an amazing package.

    However the documentation appears to be lacking in the area of helping to get started with the user interface so I think this could be a big benefit going forwards.

    e.g.

    ====================== GETTING STARTED =============================================
    1.) Create a curve with GameObject (Hierarchy->Create->Curvy->Spline)
    2.) Take any object (e.g. a simple cube), attach the FollowSpline script (select object, then -> Create->Curvy->Components->Follow Spline)
    and set it's spline property to the above spline
    3.) Hit Run and enjoy!
    4.) Read the docs and enjoy it even more!

    Well, actually it does nothing at all... unless you set the speed to something other than 0 which is the default.

    I found myself stopping the video numerous times to see what was going on with regard to affecting the control points and carrying out basic extrusions

    Also, changing the control points orientation/rotation in the video only works if you select the spline and change the Orientation to Control Points rather than Tangents which is the default.

    Also adding points like in the video is a real time saver, but it took me a while to track down the shortcut G.

    Hope you don't mind the feedback :) These are minor points as it is really impressive.

    Two other questions:
    1 With the Clone Builder, is there anyway of specifying an offset so that one could interleave multiple different meshes in different clone paths?
    2 What do you have planned for V2?

    cheers,

    Nalin
     
  36. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    To be honest I'm not sure if I understand your question. Did you checked the pmFollowSpline example? The cube's there follow their splines (either in relative or fixed speed). Does that help?
     
  37. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    @puzzlekings:

    Thanks for the feedback. Usability and UI will be greatly improved in the next version, e.g. by a simpler and more intuitive draw mode.

    Unfortunately there isn't an offset option yet.
     
  38. ChaneDev

    ChaneDev

    Joined:
    Feb 12, 2013
    Posts:
    66
    I just tried to recreate the problem I was having with objects not traversing the whole spline and I am not able to create it. Thanks for the response.
     
  39. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Thanks for the response.

    Do you have a rough idea for timescales for V2?

    cheers

    N
     
  40. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Hi Jake

    I was just wondering how it might be possible to have a gap in the extruded builder mesh? e.g. to allow for jumping by characters and cars etc.

    Ideally what I was thinking of was if a control point was flagged as inactive, then there could be a break/gap in the curve.

    Do you know how this might be possible?

    cheers

    Nalin
     
  41. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    Hi Jake,

    I'm trying to help other people with PlayMaker support for Curvy, but it's hard to be sure I'm giving out the correct answers because your documentation is not updated.

    Can you tell me just in overall terms what these 3 PlayMaker Actions are to be used for / in what situations / their individualbenefits:

    Curvy Move Along Spline Distance
    Curvy Move Along Spline Connection
    Curvy Move Along Spline


    (only the last 2 are apparently documented at http://docs.fluffyunderware.com/curvy/pmcurvy.html and it's causing some confusion - also because the naming/spelling in the documentation is different from that of the actual actions)

    Thanks!

     
  42. SerkBer

    SerkBer

    Joined:
    Jan 5, 2015
    Posts:
    1
    Hello! I have bought this tool and first of all i want to say is amazing and powefull. Good job!

    I have a question about Clone Builder. If I choose a prefab with several objects inside as "Source" it works perfectly, even if I modify the prefab and apply, all the clones along the spline gets updated. But when I push the button "Clone to an individual GameObject", all hierarchy in the detached clones and prefab dependencies gets lost.

    I wonder if I am doing something wrong, or it is a bug.

    Anyway, thank you!
     
  43. Fritsl

    Fritsl

    Joined:
    Mar 10, 2013
    Posts:
    211
    Curvy was made before Unity changed Hierarchy sorting to not be automatically alpha-numerical. And this can cause some confusion - but I do not think your issue is related to Curvy, rather to Unity's way of sorting.

    http://forum.unity3d.com/threads/unity-4-5-new-hierarchy-window-sorting.248298/

    I am constantly using Curvy like you describe, with multiple complex prefabs, and there's no trouble apart from this general Unity-sorting issue.
     
  44. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Use "Move Along Spline" as the default, unless you add/remove control points while moving - in this case use "Move Along Spline Distance". The connection variant is used to travel over connections.

    I agree that the naming is confusing. In the new version all three components are combined into a single component and I'll try to design a single action for all use cases - if that's possible with Playmaker (e.g. connection handling uses events in the new version. That's fine for scripting, but I have to check how PM can work with that system).
     
    Fritsl likes this.
  45. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I started using Curvy very recently for my 2D sci-fi shmup being released on the Wii U. If anyone is interested, here is a link to my game on IndieDB.com. There are 2 videos showing an early development version of the game. You'll see some use of Curvy with the enemy fighter flight patterns.

    http://www.indiedb.com/games/frontier-guard
     
  46. Mcg

    Mcg

    Joined:
    Mar 28, 2012
    Posts:
    112
    Hey, I was just looking at the code for following a spline on the spline walker class and trying to see a way if I can add a offset from the spline to either the left or right by a distance value but struggling to see how. Would this be possible somehow?

    Thanks!
     
  47. Fawar

    Fawar

    Joined:
    Aug 5, 2014
    Posts:
    4
    I'm actually looking around to do the following

    Generate a Spline (in editor) in 3D on which I will be able to spawn a grid-like thing that encapsulate 3 cells.
    The spline would be going threw the middle cell, right in the middle of it and the other 2 cell would be on the right and on the left of the central one.


    I would then have mutliple "short" spline that would "connect" to each other quite randomly.

    IS it something I could do with CurvySpline?
     
  48. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    @Mcg I was looking for a way to do this as well and found the Spline.GetExtrusionPoint API, and in this example it is added to FollowSpline.cs. However it may not be the most efficient way but it does work :)

    If you add this to the end of doUpdate() in FollowSpline.cs it will override & shift the position - 2nd param is distance, third is anticlockwise angle:

    Transform.position = Spline.GetExtrusionPoint(mCurrentTF,3.0f,90.0f);

    HTH

    Nalin
     
  49. Mcg

    Mcg

    Joined:
    Mar 28, 2012
    Posts:
    112

    Thanks I will try this aswell! , currently I was using translate to offset my transform but I think a distance from the spline would be better for what I need :)
     
  50. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    @puzzleking: Thanks, I was just about to post the same when I saw your answer ;)

    Yes. The first could be solved using a CloneBuilder or by code using GetExtrusionPoint() like mentioned above. Randomly add "sub" splines can be done quite easily using the API.
     
Thread Status:
Not open for further replies.