Do we've PATH like in the video below

I’ve lately seen that a few games have automatic moving on the path for the player.
Found a video for the same but on buildbox. For idea, see the video showing “Path” feature.

How to do the same in cocos2d-x? :slight_smile:

Naively? Just seq of MoveTo for each point.

Smoother? it you can try a seq of BezierTo or CatmullRomTo, CardinalSplineTo
http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animations .
https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline .

Complex? Subclassing one of these actions or create a class that manages following a path using these actions.

(BuildBox seems interesting as well. Maybe something for creator to strive for, at least some aspects, as it does seem much more like a cookie cutter game engine. Have you used it?)

Hello, @catch_up Its easy to create a custom editor with real time play functionality, I did same about a year ago, My requirements were simple, I had a Edge Shaped Path on which my player will move (Physics based). The way to accomplish it quite simple.
For Editor :-

  1. create a blank Layer/Node,
  2. Make this Layer move using swipe for ease of scrolling through level creation process(can use sliders as well).
  3. Use FileUtils::getInstance()->writeToFile(<#ValueMap &dict#>, <#const std::string &fullPath#>) to store clicks on screen and draw node to draw lines between these points for visualization of path.
  4. save ValueMap of ValueVector< Vec2 > into device storage by using FileUtils::getInstance()->writeToFile(<#ValueMap &dict#>, <#const std::string &fullPath#>) or you can also make a Manager(Singleton) to access ValueMap between different Scenes/Layers without writing / reading from disc.
  5. Play Test Button(when clicked add a new Layer for game Play).

For Game Play/Level Testing.

  1. Access points saved by reading from file saved or from Manager (Whatever you decided to follow).
  2. Get coordinates and Use DrawNode to draw path
  3. Place a Debug button to view/ hide DrawNode path.
  4. Start button:- When clicked it will follow the path Vec2 points from ValueVector.

As pointed by @stevetranby you can use whatever method as per requirement and ease of code, If you decide to use CatamullRom or Bezier Curve then you should also use them in editor to get the feeling of final result.
A sequence of MoveTo action with callback, inside callback you again run same action by updating moveTo Parameters, a dirtyish hack resembling recursion.

Hope this makes sense, :slight_smile:

Best Regards

I’ve not used it. But just for fun, I was watching some video tutorials. It’s a entity based model, just like cocos creator or unity. NO Coding is needed for this… Simple drag-drop and edit properties.
Interesting, it can make 2.5 and 2D games so much awesomly… It’s like if it was free tool. It could have drooled lof of people… I don’t know if people have used it for 3D.

I tried it because literally every game, I saw in past few months which topped the apple and play store chart is made in Buildbox… It literally looks a cool tool. I would have surely try it learning further but it’s free only for 30 days and rest is subscription. It’s costly for me and in general. Something that indie developers can’t afford at all.

I would really want developers of Cocos Creator to also have a look at it… The tool in itself looks so much cool and organized. I think, cocos creator can take UI hints from it. :slight_smile:

It’s like a developer doesn’t have to worry about rest of things but simply focus on creating his game right from the start.

@slackmoehrle

@Lazy_Gamer
@stevetranby
You both are right in implementations but in cocos2d-x 3D, there is something like path following. I was wondering if the same thing is there in cocos2d-x 2D.

What is your desired API? How’s the 3D one used different? Are you looking for steering behavior support?

Have you played the game Color Switch. It has LINE mode. Which is simply amazing for me in terms of implementation. How can I achieve with existing apis?

For idea of LINE mode, please check https://www.youtube.com/watch?v=TBhb7xb2Bfk

EDIT:
Another kind of game is this: https://www.youtube.com/watch?v=XBGW7CjrvME

Have you tried anything already? I don’t think there’s any real out-of-box without writing custom code solution with cocos2d-x, but I could be wrong?! I don’t think the 3D API gives you everything you need either, but you can always make a 2D game using 3D APIs :wink:

My thoughts (2c):

DrawNode would probably do what you want to get started, if you haven’t tried already, but in the U-Turn video you’d probably want to “clone” DrawNode so that you can have improved vertex handling: appending, cache instead of clear, etc, as well as any other optimizations.

You could also try modifying the MotionStreak class to effectively get a LineRenerer (don’t trail fade it out, but render only X segments, for example).

I don’t think you’ll find a lot of out-of-box APIs that don’t require write some code. And even if you did it would probably be limiting and you’ll eventually need to customize it and at that point you’d have been better off doing a more custom version from the beginning.

The Line Switch game could be done with DrawNode if you didn’t need the dashed line animation. For that game you can generate everything in the world and just move the world/camera around, but you’ll need to write custom animation code for moving the line segments around. Also I don’t think dashed lines capability exists out-of-box. Write your own LineRenderer.

The Line Switch touch handling could be done by a closest point on path algorithm of some kind. This you’ll mostly have to write yourself probably, but an initial working version shouldn’t be too much work.
e.g. https://stackoverflow.com/questions/18900642/get-point-on-a-path-or-polyline-which-is-closest-to-a-disconnected-point?noredirect=1&lq=1 .

One of these might give insight implementation:

  • MotionStreak (remove fade out and change removal of segments to map with some screen boundary in/out)
  • PULineEmitter/Particle3DLineStreakDemo (prob not what you want, but anim lines can be done with particles)
  • DrawNode (unfortunately based on a clear everything model, not friendly to partial changes)

(Note: A full Unity-level LineRenderer - their latest 5.5 version - would be a great addition to this engine.)
https://docs.unity3d.com/Manual/class-LineRenderer.html

There’s also the possibility you could do a game like U-Turn mostly in shader code instead of vectorized line segments, you’d just define the road and position and generate the current view every frame in the fragment shader. Might be horrendously slow, might work? No idea (just and idea :D).

U-Turn is not really path following, but more of an “old school car racing” game where the player doesn’t technically move in the game world. The “road” is just redrawn in a manner that fakes movement. Especially if it’s an “infinite runner” type where you can technically play forever.

1 Like