[solved] Retrieving player object from player body

runevision

13-05-2006 11:31:13

This is a design-question really, but you might have some good advice. :)

In our game we have a player object which has as members an OgreNewt Body, a visual Instance, some methods and many other things.

Now, given a collision between the player's body and a different body, we want one of the player object's methods to be called. However, the ContactCallback only gives us the player Body, not the player object, so we don't have direct access to the player object and its methods.

So how can we get a hold of the player object given just its body in a ContactCallback? What would you do?

There is more than one player object, so it won't work to for example just retrieve THE player object from a singleton class or similar.

Making the player object inherit from the Body class will make a lot of fuss with the constructors, so we'd like to avoid that if possible.

Thanks in advance,
Rune

runevision

13-05-2006 13:10:34

Okay, I found out this is exactly what the body->setUserData() and body->getUserData() is for. It works nicely now. :)

Rune