Mod to Speedometer HUD, works with mounted players
by Kent Butler · 11/12/2007 (1:45 pm) · 1 comments
We recently integrated vehicles into a basic FPS setup using the method described in this resource
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3925 which mounts the player to the vehicle. We found that the guiSpeedometer class would not render in this configuration. It was pretty apparent why:
My quick fix was to modify the guiSpeedometer.cc file to read the speed from a player's mount if that mount is a vehicle. I also switched things up a bit so that the .png will display even if there is not a valid control object (so at least you know the control is there). This is not too elegant, but it seems to work.
in game\vehicles\guiSpeedometer.cc find:
and change the BOLD part to
I couldn't find the issue mentioned anywhere so I figured this might help someone. I'm not that familiar with torque, so it may not be the best approach. If there is a better way to do this ... please comment!
Update: The original post incorrectly linked to a different "mount vehicle in FPS" resource than the one we actually used. The link has been corrected.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3925 which mounts the player to the vehicle. We found that the guiSpeedometer class would not render in this configuration. It was pretty apparent why:
Quote:This gui displays the speed of the current Vehicle based control object. This control only works if a server connection exists and it's control object is a vehicle. If either of these requirements is false, the control is not rendered.In this case, the control object is the player, not the vehicle. So the gui doesn't render.
My quick fix was to modify the guiSpeedometer.cc file to read the speed from a player's mount if that mount is a vehicle. I also switched things up a bit so that the .png will display even if there is not a valid control object (so at least you know the control is there). This is not too elegant, but it seems to work.
in game\vehicles\guiSpeedometer.cc find:
/**
Gui onRender method.
Renders a health bar with filled background and border.
*/
void GuiSpeedometerHud::onRender(Point2I offset, const RectI &updateRect)
{
[b]
// Must have a connection and player control object
GameConnection* conn = GameConnection::getConnectionToServer();
if (!conn)
return;
Vehicle* control = dynamic_cast<Vehicle*>(conn->getControlObject());
if (!control)
return;
Parent::onRender(offset,updateRect);
[/b]
// Use the vehicle's velocity as it's speed...and change the BOLD part to
Parent::onRender(offset,updateRect);
// Must have a connection and player control object
GameConnection* conn = GameConnection::getConnectionToServer();
if (!conn){
return;
}
Vehicle* control = dynamic_cast<Vehicle*>(conn->getControlObject());
if (!control){
// The control object is not a vehicle ... see if it is a mounted player
Player* p = dynamic_cast<Player*>(conn->getControlObject());
if (!p){
// Not a player or a vehicle ... get outta here
return;
}
if (!p->isMounted())
return; // If the player isn't mounted there is no vehicle
control = dynamic_cast<Vehicle*>(p->getObjectMount());
if (!control)
return; // Final failure ... really no control object
}NOTE: I'm not sure why the comments reference a "health bar", but that's what is in my stock 1.52 version. It's really from the speedometer file, I imagine they prototyped off the healthbarI couldn't find the issue mentioned anywhere so I figured this might help someone. I'm not that familiar with torque, so it may not be the best approach. If there is a better way to do this ... please comment!
Update: The original post incorrectly linked to a different "mount vehicle in FPS" resource than the one we actually used. The link has been corrected.
About the author

Torque Owner Kim Skogen
However I didnt want my speedomter to show outside a car, which I easily fixed by moving the Parent::onRender(offset,updateRect); line from the top to below the rest of your source. I also had to add #include "game/player.h" at the top to make it work.
Thanks for sharing.