Sign in to follow this  
drwbns

how to handle character to vehicle controls?

Recommended Posts

drwbns    103
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
Ashaman73    13715
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this