Follow path behavior

0 favourites
From the Asset Store
Run, jump over or on enemies and reach the path’s end as fast as you can!
  • The sprites seem to spend a constant time between points. This means they speed up dramatically if the points a far apart and slow right down if the the points are close. Any way of altering the spline formula to account for this and get a constant speed?

  • The simplest way I have found is to decompose the spline path into a polyline and move along that line.

    Here I made it calculate the polyline as needed.

    /examples%209/catmullrom_constant_speed.capx

    https://www.dropbox.com/s/faf05eygw363j ... .capx?dl=0

    Note: It only works with positive speeds atm.

  • That's definitely constant. Great work - but... question... you've got a blank sub-event, is that needed? and I can't work out why the arrows are jerky. FPS seems fine.

  • The blank event is just an artifact of converting my first example you can safely move the actions to the event above.

    I was noticing the jerky motion as well and found that if you remove "stop loop" from event 6 they move much smoother.

    It also goes smoother if you add a smaller value to "t" in event 5, of course you will have to increase the number in the "repeat" condition since the Sprite will be moving over more line segments.

  • Oh my god... this is serious o_O

    Great work man.

  • Insane code! I'm using this as well. Good job R0J0hound!

  • That's great. Any plan to release this as a behavior plugin?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This. This is awesome.

  • So, what if I'd need to remove one of the objects from the string, or add one, somewhere in the middle? Can this be accomplished?

  • Really appreciate this! Thanks!

  • xyboox

    Yes, that is possible, but instead of using the IID to access the points store all the points in an array.

    Then do these changes to the expressions:

    p(n).x -> Array.At(n % Array.Width, 0)

    p(n).y -> Array.At(n % Array.Width, 1)

    p(n+1).x -> Array.At((n+1) % Array.Width, 0)

    p(n+1).y -> Array.At((n+1) % Array.Width, 1)

    p(n-1).x -> Array.At((n-1) % Array.Width, 0)

    p(n-1).y -> Array.At((n-1) % Array.Width, 1)

  • Thanks R0J0hound, but I believe this would ensure a dynamic built path ( which is also very useful! ). Maybe I wasn't clear enough earlier: I need to remove and/or add elements to the string of sprites following the path, not elements of the path itself. The challenge would be to make space for the new come or to fill the gap made by the destruction of a sprite.

  • Here is a way to do a spline though waypoints:

    http://dl.dropbox.com/u/5426011/examples%208/catmullrom.capx

    A plugin could be made to hide the formula, but there isn't a way to make an in IDE node editor at this time.

    Question is will we ever get that ability?

    Perhaps someone should come up with an external editor. It's not like it has to be just for paths.

  • Sorry to bump and old thread. I'm trying to use ROJOhound's formula for an NPC. Does anybody know how to make is so when the NPC is destroyed, it returns to the spawning position. At the moment it just picks up where it left off.

  • How do you set an instance variable to <varies>. I sorta get how it comes to that, but what circumstances result in <varies> being displayed in the properties bar? Like, if I edited the initial value, how do I get it back to <varies>?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)