Keep basic game physics separate from basic game object? [on hold]
- by metamorphosis
If anybody has dealt with a similar situation I'd be interested in your experience/wisdom,
I'm developing a 2D game library in C++,
I have game objects which have very basic physics,
they also have movement classes attached to differing states, for example, a different movement type based on whether the character is jumping, on ice, whatever.
In terms of storing velocity and acceleration impulses, are they best held by the object? Or by the associated movement class?
The reason I ask is that I can see advantages to both approaches-
if you store physics data in the movement class, you have to pass physics information between class instances when a state change occurs (ie. impulses, gravity etc) but the class has total control over whether those physics are updated or not. An obvious example of how this would be useful was if an object was affected by something which caused it to ignore gravity, or something like that.
on the other hand if you store the physics data in the object class, it feels more logical, you don't have to go around passing physics impulses and gravity etc, however the control that the movement class has over the object's physics becomes more convoluted.
Basically the difference is between:
object->physics stacks (acceleration impulses etc)
->physics functions
->movement type
<-movement type makes physics function calls through object
and
object->movement type->physics stacks
->physics functions
->object forwards external physics calls onto movement type
->object transfers physics stacks between movement types when state change occurs
Are there best practices here?