[1.1b2] Vehicle camera disabled and bug with Player::setControlObject()
by Jason Eubank · in Torque 3D Professional · 09/18/2010 (5:18 pm) · 8 replies
Hello,
I tried searching for some of these issues but didn't have much luck, so sorry if I am re-posting anything.
I have been messing around with the Buggy in my "Full" project terrain map and I noticed that when setting cameraRoll to false in WheeledVehicleData(DefaultCar) it had no effect and the camera still rolled when the vehicle did. This is because in C++ the Player class is not overriding getCameraTransform(); this is needed so that when the player is mounted to a vehicle the Player class can call this function on the controlling object. A simple fix for this is to declare and implement the getCameraTransform(F32* pos,MatrixF* mat) in the Player class, my implementation looks like this:
After you hook this code up the vehicle camera takes over and you get several cool features; i.e. all these parameters in the WheeledVehicleData datablock:
cameraRoll = false; // Roll the camera with the vehicle
cameraMaxDist = 8.0; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.26; // Velocity lag of camera
cameraDecay = 1.25; // Decay per sec. rate of velocity lag
However this also comes with a bug. While driving the vehicle the client will randomly receive a network packet that calls void Player::setControlObject(ShapeBase* obj); once this happens advanceTime() is no longer called on the client side vehicle object and the camera gets really wonky (this is because the cameraDecay feature accumulates on the client Vehicle object and advanceTime() is what decrements it). Unfortunately I can not find the cause this packet is sent or why calling setControlObject() while driving the vehicle is necessary. Assuming you hooked up the vehicle camera you will know when you have reproduced this bug because the vehicles wheels stop rotating (although they still turn from steering).
I hope someone can repro this, I have made no modifications to my engine code from 1.1b2 other than the above mentioned to get the vehicle camera working. I also have not made any script modifications from the Full template and simply dropped a vehicle in the terrain map.
Thanks!
I tried searching for some of these issues but didn't have much luck, so sorry if I am re-posting anything.
I have been messing around with the Buggy in my "Full" project terrain map and I noticed that when setting cameraRoll to false in WheeledVehicleData(DefaultCar) it had no effect and the camera still rolled when the vehicle did. This is because in C++ the Player class is not overriding getCameraTransform(); this is needed so that when the player is mounted to a vehicle the Player class can call this function on the controlling object. A simple fix for this is to declare and implement the getCameraTransform(F32* pos,MatrixF* mat) in the Player class, my implementation looks like this:
void Player::getCameraTransform(F32* pos,MatrixF* mat)
{
if (!mControlObject.isNull() && mControlObject == getObjectMount()) {
mControlObject->getCameraTransform(pos, mat);
return;
}
ShapeBase::getCameraTransform(pos, mat);
}After you hook this code up the vehicle camera takes over and you get several cool features; i.e. all these parameters in the WheeledVehicleData datablock:
cameraRoll = false; // Roll the camera with the vehicle
cameraMaxDist = 8.0; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.26; // Velocity lag of camera
cameraDecay = 1.25; // Decay per sec. rate of velocity lag
However this also comes with a bug. While driving the vehicle the client will randomly receive a network packet that calls void Player::setControlObject(ShapeBase* obj); once this happens advanceTime() is no longer called on the client side vehicle object and the camera gets really wonky (this is because the cameraDecay feature accumulates on the client Vehicle object and advanceTime() is what decrements it). Unfortunately I can not find the cause this packet is sent or why calling setControlObject() while driving the vehicle is necessary. Assuming you hooked up the vehicle camera you will know when you have reproduced this bug because the vehicles wheels stop rotating (although they still turn from steering).
I hope someone can repro this, I have made no modifications to my engine code from 1.1b2 other than the above mentioned to get the vehicle camera working. I also have not made any script modifications from the Full template and simply dropped a vehicle in the terrain map.
Thanks!
About the author
Programmer at Certain Affinity. Titles shipped: Age of Booty (XBLA), Left 4 Dead, Call of Duty: World At War, Halo Waypoint, CoD: Black Ops, Halo: Reach Defiant Map Pack, Halo: Combat Evolved Anniversary
#2
09/20/2010 (10:43 pm)
This sounds like a duplicate of www.torquepowered.com/community/forums/viewthread/111049.
#3
How about the missing override of Player::getCameraTransform()? This is needed to enable the vehicle camera and follows the paradigm found in Player::getCameraParameters(). I think this used to be here and was removed at some point, possibly only exists in TGE?
09/20/2010 (11:31 pm)
Yeah the bug portion definitely is, hopefully my repro steps will help track down a fix.How about the missing override of Player::getCameraTransform()? This is needed to enable the vehicle camera and follows the paradigm found in Player::getCameraParameters(). I think this used to be here and was removed at some point, possibly only exists in TGE?
#4
I added the suggested code snippet to player.cpp to my 1.1b3 project but I don't know exactly how to declare getCameraTransform properly.
<
\Engine\source\T3D\player.cpp(3645) : error C2509: 'getCameraTransform' : member function not declared in 'Player'
>
I thought it would be something like this:
<
// Hack for vehicle Camera
static F32 getCameraTransform = 1.0f;
>
Any help would be appreciated.
11/28/2010 (6:29 am)
This vehicle camera fix looks like the fix I need, the only problem is I'm not smart enough to get it to work. Let me just start by saying I'm not a programmer.I added the suggested code snippet to player.cpp to my 1.1b3 project but I don't know exactly how to declare getCameraTransform properly.
<
\Engine\source\T3D\player.cpp(3645) : error C2509: 'getCameraTransform' : member function not declared in 'Player'
>
I thought it would be something like this:
<
// Hack for vehicle Camera
static F32 getCameraTransform = 1.0f;
>
Any help would be appreciated.
#5
11/29/2010 (2:57 pm)
You need to declare this in a public section of your Player class declaration in player.h:void getCameraTransform(F32* pos,MatrixF* mat);
#6
11/29/2010 (4:03 pm)
Perfect! Thanks Konrad and thanks Jason for the original post. The fix works pretty well and seems like it should be a mandatory fix for future versions (if there are any).
#7
I agree, this definitely needs to be addressed in a future version as well as the bug that makes the animations stop (and everything else seems to stop working with the vehicle too).
I found that you can easily reset the bug by simply exiting/entering the vehicle after the bug has occured.
I will reply if I get some more time to debug the problems fully.
11/29/2010 (4:27 pm)
Just saw this was updated, thanks Konrad for the help.I agree, this definitely needs to be addressed in a future version as well as the bug that makes the animations stop (and everything else seems to stop working with the vehicle too).
I found that you can easily reset the bug by simply exiting/entering the vehicle after the bug has occured.
I will reply if I get some more time to debug the problems fully.
#8
12/06/2010 (9:07 pm)
I believe the camera setup was intentional, when mounting a Player you retain the Player's PoV. If you want to use the Vehicle's camera you can make it the client's control object. Use %player.client.setControlObject(%vehicle) instead of %player.setControlObject(%vehicle). This basically makes the Vehicle your player so you'll use its PoV.
Torque Owner Jason Eubank
Studeeoh Solo