Game Development Community

How do I get the Player object on client side ?

by Ali Khan · in Torque Game Engine · 11/22/2006 (9:20 am) · 3 replies

Hello All,

I need to get the Player object pointer on the client side. This player object will be the ghosted image of the player object that represents this client on the server side. But I am unable to do so. Basically I need to access the player object on the client side so that I can perform some client side processing.

I have tried a few things,

1.

GameConnection* conn = GameConnection::getConnectionToServer();
ShapeBase* ControlObj = conn->getControlObject();

This works unless I mount my player on a vehicle and set it as the control object for the client. I need to set the vehicle as the control object to be able to drive it.

2.

I have also tried to match the object IDs on the server and client, but they come out to be different. Basically by this matching I was planning to do something like the server sending its player ID in a command to client and the client will then lookup the SimObject for that ID. But since the IDs do not match I can't do this either.



Anyone has any idea about this, please let me know.

Thanks.

Ali Khan.

#1
11/22/2006 (9:26 am)
I think torque allready does all this out of the box....what is it your trying to do?


Need...coffee...
#2
11/22/2006 (10:51 am)
To get the clientside player object (the ghost of the true player object, which resides on the server), you can do this from your clientside scripts:

%clientPlayer = ServerConnection.getControlObject();

(Assuming the player is your control object)

However, unless you are doing something really special case, you usually don't want to do the above. All gameplay logic takes place on the server, and the server automatically updates the client's objects. This means you should be acting on the server's objects to make gameplay changes.

Take a look at /starter.fps/server/scripts/game.cs for examples of setting up a control object. Search for "setControlObject"
#3
11/24/2006 (3:01 am)
Well, what you should do is use the method you described:

GameConnection* conn = GameConnection::getConnectionToServer();
ShapeBase* ControlObj = conn->getControlObject();

And then check to see if you've gotten a Vehicle or a Player. If it's a Player, you're good to go. If it's a vehicle, you'll want to search the mounted objects for your player, which isn't particularly difficult (for most games, you can assume the driver is always mounted to node 0, or whatever you've picked as the "driver" node).