Game Development Community

Setting the Control Object

by Doug Coward · in Torque Game Engine Advanced · 05/04/2007 (3:34 pm) · 2 replies

I'm having a problem understanding the setControlObject mechanism.
The context is vehicle mounting, unmounting, and changing seats.

The confusing part to me is, that there is a GameConnection setControlObject function and a ShapeBase/Player setControlObject function. In the script it appears (to me) that the GameConnection function is called most often
like this -
%obj.client.setControlObject(%vehicle); Or %client.setControlObject(%vehicle);

But some functions like Armor::onMount appear (to me) to call the Player::setControlObject
like this -
%obj.setControlObject(%vehicle);

And adding to the confusion is the fact that some of these calls may have been introduced by vehicle resources or vehicle packs.

Can someone explain which setControlObject function to use, and why?

#1
05/07/2007 (4:59 am)
Looking through the code, they pretty much do the same thing. When you're a player you already have an control object for your connection, whereas with the Connection, it can be nothing.

So for vehicle mounting I would assume you should use player::SetControlObject.
#2
05/08/2007 (2:41 pm)
Actually, they work quite differently and having them mixed was really messing things up. And now I think I understand how they need to be used.

The GameConnection setControlObject clears all the previous control objects and sets a relationship between the GameConnection and the new ShapeBase object it is controlling (the player object). This is meant to be called like when the player object enters the game to establish the shape that the client is controlling.

The ShapeBase setControlObject sets a relationship between the client controlled shape and a new ShapeBase object it wants to control. This is meant for a temporary transfer of control like controlling a vehicle. And it provides the new control object (vehicle) with a pointer back to the client controlled shape called mControllingObject.

This all allows the client to control any shape object without the mess of a long chain of control objects. Simply, the client points to the player object and the player object points to the object it wants to control.
Calls to the GameConnection setControlObject during mounting (that I believe came from a vehicle content pack) really messed me up and kept me from understanding this for a long time.