Sign in to follow this  
nims92

Train like movement in a 2D game

Recommended Posts

I am developing a 2D game using Cocos2d-X in C++ language. In my game, I need to implement train movement.

Here is the image about the output I want to achieve:

lEMqj.png
I tried to do the above moment using Actions from Cocos2d-X. However on the curved part of the tracks, the train movement is not accurate.

I  have following questions:

  1. Is it a right method to create the train movement using Actions? If no, which alternate methods/algorithms can be used?
  2. I wanted achieve train movement similar to Mini Metro game. How to create such train movement in Cocos2D-X?

I would appreciate any suggestions/thoughts on this topic.

Share this post


Link to post
Share on other sites

I suppose you could use splines, and each wagon is comprised of two points on the spline, from which you can calculate the rotation angle quite easily. Then you just place the sprite at one of the points and rotate it :)

Share this post


Link to post
Share on other sites

apparently, there's no easy way to do trains.

for a 90 degree right turn, you need the center of the turn, and the radius.  you translate a car from the center by the radius, then rotate it around the center.  how much you rotate depends on its speed around the curve. the length of the curve is pi*r/2 units per 90 degrees. if the train moves x units per turn,  thats x / pi*r/2 = y / 90. or  x / (pi*r/2) / 90 = y = degrees rotated per turn.  same idea for 45 degree turns etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this