I was always wondering how trains or other moving platforms are implemented in games. For example: there a many games where you can walk on the back of a truck or on a train that starts to move. During this time you can freely walk around like you could on normal map. (I don't think about rail-shooter parts were you just fire a gun or sit still somewhere). Of course you could load a new map that just gives you the feeling of moving where actually the map is pure static, but that's not what I mean.

How does the game translates all the vehicle movements to the actual position of the entities that are on it? Especially AI, collision (you don't fall throu the platform due to some glitches) and smooth rendering (some games screw this up and you see the entities bouncing up and down).

If I would do this than I would probably use an own coordinate system for the platform and translate this into the "real" on. But I have no idea how this would look since you would have to store the "belonging" platform for every entitie and I think there's probably a better solution.

I think a good example is the transport system in World of Warcraft. The NPCs even have waypoints during flights and you can trade with them. It actually feels like on the ground.

I would really like to get some links with detailed explanations if there are any.

  • \$\begingroup\$ Do these questions help? gamedev.stackexchange.com/questions/3964/… and gamedev.stackexchange.com/questions/15180/… \$\endgroup\$ – congusbongus May 24 '13 at 1:35
  • \$\begingroup\$ @CongXu Sort of, but both apply to rather simple games where you just have to handle velocity and the moving platform. The idea with with a tree design is very nice but seems very complicated if you would like to make the npcs move and even follow AI scripts. I'm not sure if this is the only way of doing it and I couln't even find much with google so I'm hoping to get a few answers here. \$\endgroup\$ – Chris May 24 '13 at 1:41

It varies by game. Some try to model things physically using a physics engine and rely on friction to keep things moved together. This can be a bit fragile.

A more common technique that is used even in games (especially ones that don't have real physics support) is to just parent objects to others. If game logic detects that I've "landed" on a moving platform of some kind, then my avatar is parented to that object. My avatar's position is now relative to that moving platform so I move with it. This connection is then removed when I am no longer in contact with the platform (I jump or walk off the edge) in most cases. Some games will keep me parented if I jump but stay over the platform while in the air, making it so that I move with the platform even when jumping, while others do things more physically and apply the parent's horizontal velocity to my avatar if I jump, and yet others make all jumps purely vertical irrespective of the speed of the platform I might have been on. This technique makes the implementation super-easy and relatively bug-free although it can at times lead to physical inaccuracies (some of which might actually be desirable).

In some cases, there isn't even a moving platform at all, but rather the background objects around the platform I'm on are moved to give the visual sense of movement. This is common in cases where the entire usable play area is on some kind of moving platform, e.g. a fight on the top of train where falling off is just insta-death.

  • \$\begingroup\$ So you actualy move the "mounted" entities relatively to the moving one and transform this relative coordinates back into absolute ones when needed? So how would AI work in this case? Would I need to thread the moving platform the same way as the world and do AI calculations based opon this relative coordinate system? Sounds like there are many things that could go wrong. Do you know of a good implementation or some sort of documentation. Just to get an idea of how the code could look like? \$\endgroup\$ – Chris May 24 '13 at 1:46
  • \$\begingroup\$ AI is fairly agnostic to the parenting; it can just work in world coordinates. It would likewise be agnostic to other parenting which you'll end up using in most complex game worlds for a variety of things. Yes, there can be some things that work weird; again, the technique used depends on the game. A few seconds of Googling indicates there's a lot of videos on moving platform tutorials for UDK/Unity/Havok/etc.; find one similar to your game using your engine or something similar and go from there. \$\endgroup\$ – Sean Middleditch May 24 '13 at 7:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.