[Design] Changing the player I am controlling

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
User avatar
gbisocoli
Kobold
Posts: 39
Joined: Sat Nov 01, 2008 1:24 am

[Design] Changing the player I am controlling

Post by gbisocoli » Thu Sep 11, 2014 9:02 pm

Hi, I have a design problem (I am using Ogre + NxOgre):

I'm controlling a soccer team, I control one player at a time and I can change between them when I click them (I change the Player I am controlling in game). Just like any other soccer game out there (FIFA, PES). The thing is that in my design I am using a Character Controller for the player I am controlling and a simple Capsule for the rest of the players, I have some options on how to do the swaping of the controlling player:

1- make a change in position between the player I am controlling (Character Controller) and the player I will control, this way I'm still controlling the same entity but it seems that I change to another one. This is the one I implemented, I feel this is not a good design besides sometimes when I change players one entity flies away :lol:

2- make all players a Character Controller but handle one of them by user and the others by AI (this might work)

3- make all players a Capsule and handle one of them by user.

Which one you think is better? Maybe you have a better option?
0 x

User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
Contact:

Re: [Design] Changing the player I am controlling

Post by Klaim » Thu Sep 11, 2014 11:25 pm

As always in 3rd person games, making the camera a separated game element with it's own behaviour will help you a lot.

Have your characters behave separately. Then, have the camera behave separately too. Just make sure the camera have a pointer to the character or other object it should be "relative" to.
Then when you change character, tell the camera to change the target character.
To have a smooth transition, use (for example) steering behaviours or linear interpolation to the wanted camera position instead of setting the camera directly at that position. Basically, have some code moving the camera to a target position as fast as possible, but not instantaneously. Then this target position will depend on what is the currently focused-on object/character, and where should the camera be placed relative to it.

The camera, then, don't have a clue what it is focused on, it just know focused-on position and orientation and the camera position and orientation relative to the focused-on object.
Your characters can be whatever you like then.
0 x

User avatar
gbisocoli
Kobold
Posts: 39
Joined: Sat Nov 01, 2008 1:24 am

Re: [Design] Changing the player I am controlling

Post by gbisocoli » Fri Sep 12, 2014 1:10 am

The camera is not the problem, that's working ok, when I change player the camera follows correctly.

The problem is in the physical object representing each player, I have 10 Bodies (Body*) and 1 Character Controller (AnimatedCharacter*), they are totally different physics entities, so when I change from the Character Controller I am controlling to any of the other bodies, I have to make a change in the system so the new player I am controlling is now a Character Controller and the previous one is a body. And I fail to see a simple way to do this, I think I have to change the design, making all players a Character Controller may be an option.

Code: Select all

class HumanPlayerBase: public PlayerBase
{
	public:
             // ...
	protected:
		Critter::AnimatedCharacter*     mCharacter;
		MyCharacterInputHelper   mCharacterInputHelper; // to inject movement to the Character
};

Code: Select all

class AIPlayerBase: public PlayerBase
{
	public:
             // ...
	protected:
		Critter::Body*		mBody;
};
*Critter is NxOgre.

I hope this clarifies the problem, it's kind of difficult to explain. I'm looking for a common way of doing this, maybe some of you know how they do this in other sports games.
0 x

NotCamelCase
Greenskin
Posts: 140
Joined: Sun Feb 03, 2013 6:32 pm
x 1

Re: [Design] Changing the player I am controlling

Post by NotCamelCase » Fri Sep 12, 2014 3:41 pm

I don't know how sport games handle player physics though using capsule as the collision shape for players seems problematic from here. I think you'll need wider collision resolution than checking capsule vs capsule or capsule vs sphere during game.
0 x
Check out my projects: https://github.com/NotCamelCase

drwbns
Orc Shaman
Posts: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

Re: [Design] Changing the player I am controlling

Post by drwbns » Fri Sep 12, 2014 10:10 pm

Sounds like it's just a design issue. I don't think you should have an AIcontrolledPlayer and a HumanControlledPlayer classes. You should probably just have a mController member in your generic AnimatedCharacter class that is a pointer to either a human player or an AI player. Your player class should contain an animatedCharacter pointer so you know who your controlling and can act upon it. AI should most likely have a manager class that deals with them directly and can also swap out AI for a human player. This probably isn't exactly what you need but I'm just throwing some ideas out there to fix your design. In my own engine, I'm inheriting from an IControllable class that I deal with in the same way I mentioned.
0 x

User avatar
gbisocoli
Kobold
Posts: 39
Joined: Sat Nov 01, 2008 1:24 am

Re: [Design] Changing the player I am controlling

Post by gbisocoli » Sat Sep 13, 2014 3:19 am

NotCamelCase wrote:I don't know how sport games handle player physics though using capsule as the collision shape for players seems problematic from here. I think you'll need wider collision resolution than checking capsule vs capsule or capsule vs sphere during game.
Fortunately I'm using nVidia PhysX (through NxOgre) so that's not a problem. My idea is to make simple characters (1, 2 or 3 shapes max per character), PhysX can handle that :D
drwbns wrote:Sounds like it's just a design issue. I don't think you should have an AIcontrolledPlayer and a HumanControlledPlayer classes. You should probably just have a mController member in your generic AnimatedCharacter class that is a pointer to either a human player or an AI player. Your player class should contain an animatedCharacter pointer so you know who your controlling and can act upon it. AI should most likely have a manager class that deals with them directly and can also swap out AI for a human player. This probably isn't exactly what you need but I'm just throwing some ideas out there to fix your design. In my own engine, I'm inheriting from an IControllable class that I deal with in the same way I mentioned.
Yes, something like that might work, I think I can make all players a generic class and have a pointer to a User-controlled entity and a AI-controlled entity and switch them as I need. Next step in my project is implement AI (Steering Behaviors, State Clase, etc...) so that will control the switching. Thanks! :D
0 x

Post Reply