# Train like movement in a 2D game

This topic is 614 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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:

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 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 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.

1. 1
2. 2
3. 3
Rutin
20
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633656
• Total Posts
3013190
×