Character to vehicle controllers
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Character to vehicle controllers
Hey guys, I've been reading a lot lately on component or data-driven class designs and then I thought - How would I implement a character controller that can also switch to a vehicle controller - e.g. a player can run or get in a car and drive. I thought about maybe a generic controller class that a character and vehicle class inherit from but my thinking is a little fuzzy on how to switch the controller when appropriate - e.g , getting in or out of the car. First thoughts are having a player->getInVehicle(Vehicle * vehicleToGetIn) function that sets a Vehicle * dataMember and also changes a vehicleToGetIn->driver dataMember. It seems strange to set data members for 2 different objects though. Maybe have a vehicle function called getIn(Character * character) that calls character->setController(new VehicleController()); Any thoughts on how this should be setup properly? Thanks!
-
- OGRE Expert User
- Posts: 1920
- Joined: Sun Feb 19, 2012 9:24 pm
- Location: Russia
- x 201
Re: Character to vehicle controllers
So even with a vast amount of material about component and data-driven designs none of it ever solved that issue? What's the point then?
-
- Goblin
- Posts: 287
- Joined: Mon Dec 08, 2008 4:49 pm
- x 10
Re: Character to vehicle controllers
I think you would want an interface Controllable, which is implemented by person and vehicle. And you would have a Controller interface / abstract class. The Controllable would have generic movement methods like turn, move, jump. The controller class has subclasses for each input type (joystick, mouse, touch), and calls the methods of the Controllable it controls.
The controllable then translates those methods to actual movement and behavior (using the turn input for steering for example)
Then you would say controller->setControllable(vehicle), after which all the events of the controller would be passed to the vehicle instead of to the character.
You might want to look at the way unity3d handles components. I find that useful examples
The controllable then translates those methods to actual movement and behavior (using the turn input for steering for example)
Then you would say controller->setControllable(vehicle), after which all the events of the controller would be passed to the vehicle instead of to the character.
You might want to look at the way unity3d handles components. I find that useful examples
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Re: Character to vehicle controllers
I think you're referring to a style such as - http://martindevans.appspot.com/blog/pe ... 3N0GIH3Agw Isn't unity closed source unless you bought a license? Do you have a source code example for design style you are reffering to? The questions I have are - how do I seperate the way a player turns vs the way a car turns? A player can rotate in place but a car can only turn it wheels in place...Just some initial thoughts
I found some generic controllable code but your saying to actually add movements to it like jump, turn, moveForward ? -
I think I'm just reading too many sources that say to implement components with behaviours that modify the data ( such as you saying a controllable should implement the movement behaviours ) but I've also read that the components should not modify data...hence the confusion
I found some generic controllable code but your saying to actually add movements to it like jump, turn, moveForward ? -
Code: Select all
class Controllable
{
public:
Controllable(Controller &controller) : controller_(controller) {}
Controller *getController() const;
void setController(Controller *controller);
void jump();
void turn();
private:
Controller *controller_;
};
Last edited by drwbns on Tue Sep 11, 2012 6:19 pm, edited 4 times in total.
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Re: Character to vehicle controllers
Are there any good books and/or articles you can reference that aid in creating component based architectures?
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Re: Character to vehicle controllers
Does anyone know of a design example that jonim8or is reffering to? I still need help with this. I'm trying to do what bstone posted here but I'm really new at that style of design http://www.ogre3d.org/forums/viewtopic. ... 29#p458355