• Advertisement
Sign in to follow this  

how to handle character to vehicle controls?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I was wondering how to structure classes that can handle player movement but also allow to switch to vehicle movements. I found a post here that looks correct, but it's left me baffled as a novice. Any further explanations to this system?

[url="http://www.ogre3d.org/forums/viewtopic.php?f=10&t=70229#p458355"]http://www.ogre3d.org/forums/viewtopic.php?f=10&t=70229#p458355[/url]

Share this post


Link to post
Share on other sites
You can define an controller interface, which controls the movement of an entity depending on given input, like

[CODE]

class ControllerInterface
{
void inputForward() = 0;
void inputLeft() = 0;
}
[/CODE]

Then you can inherit and implement this interface for different game entities.

[CODE]

class CarController : ControllerInterface
{
....
}
class CharacterController : ControllerInterface
{
....
}

[/CODE]
In your player class switch the controller depending on the players state:

[CODE]

class Player
{
CharacterController charController;
CarController carController;
bool inCar;

ControllerInterface getController() {
return inCar ? carController : charController;
}
}

[/CODE]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement