The order in which game objects are updated can affect the way objects interact with each other. Ideally, each object's A.I. will run only once per frame, so we can assume that objects that can affect others (mainly their position, but other attributes too) should be updated first. Moving platforms, for example: if the player is standing on a moving platform and the platform is updated first, all the player's A.I. has to do is apply the same displacement that was applied to the platform, before running its regular physics code.
But what about objects that can affect each other, such as enemies and the player, that can hurt each other? Depending on who's updated first, there may be a 1-frame delay before a collision between them is handled. This is not such a big problem, the only side effect is that sometimes we see the objects overlapping for a frame and sometimes we don't, and that's hardly noticeable.
There are more complicated cases, such as blocks that can be pushed by the player but can also carry the player. When the player is pushing the block, the player's A.I. should run first, so the block can copy its displacement. When the player is riding the block, however, it's the player that has to copy the block's displacement.
In my engine, I have a number of object groups that I update in order, so I can handle the block issue by moving the block between different groups depending on its state, this is fast and not such a big deal.
I do wonder how other programmers handle these issues, though. Do you visit objects more than once? Do you update objects out of order when necessary? What are other possible solutions to handle object interactions?
Note that some of the problems I presented above exist only because I'm trying to program objects in a way that only the object itself can alter its state. Objects can consult the state of other objects, but they can't change anything. That's a way to keep each object's code centralized, but I'm not sure that's the most accurate model of the real world, though... When an object pushes another, it does in fact modify that object's position, regardless of what it's doing.
But what about objects that can affect each other, such as enemies and the player, that can hurt each other? Depending on who's updated first, there may be a 1-frame delay before a collision between them is handled. This is not such a big problem, the only side effect is that sometimes we see the objects overlapping for a frame and sometimes we don't, and that's hardly noticeable.
There are more complicated cases, such as blocks that can be pushed by the player but can also carry the player. When the player is pushing the block, the player's A.I. should run first, so the block can copy its displacement. When the player is riding the block, however, it's the player that has to copy the block's displacement.
In my engine, I have a number of object groups that I update in order, so I can handle the block issue by moving the block between different groups depending on its state, this is fast and not such a big deal.
I do wonder how other programmers handle these issues, though. Do you visit objects more than once? Do you update objects out of order when necessary? What are other possible solutions to handle object interactions?
Note that some of the problems I presented above exist only because I'm trying to program objects in a way that only the object itself can alter its state. Objects can consult the state of other objects, but they can't change anything. That's a way to keep each object's code centralized, but I'm not sure that's the most accurate model of the real world, though... When an object pushes another, it does in fact modify that object's position, regardless of what it's doing.