Game Development Community

Resetcar

by CodingChris · in Torque Game Engine · 09/09/2007 (1:52 am) · 2 replies

Hi,
I'm trying to add a resetcar function to my game.
Here's my code:
function resetcar()
{
setloc($check);
}
function setLoc(%newpos)
{
	commandToServer('RelocatePlayer', %newpos) ;
}

function getLoc()
{
	echo(ServerConnection.getControlObject().getTransform());
}
function serverCmdRelocatePlayer(%client, %newpos)
{
	%client.player.setTransform(%newpos);
}

This doesn't work, but I don't know why...

#1
09/09/2007 (2:04 am)
I can't see where you're obtaining the position in the first function, resetCar()? Why are you using a global variable, $check and how and where is the value of $check being obtained?

The getLoc() function is never being called and doesn't do anything aside from echo out to the console - and the way you've done it won't work across a network.

If you're just trying to reset the car if it's flipped upside down, do this:
//-----------------------------------------------------------------------------

// Used to flip the car over if it manages to get stuck upside down
function serverCmdresetCar(%client)
{
   %car = %client.getControlObject();

   if (%car.getClassName() $= "WheeledVehicle")
   {
      %carPos = %car.getPosition();
      %carPos = VectorAdd(%carPos, "0 0 3");

      %car.setTransform(%carPos SPC "0 0 1 0");
   }
}

// The key command for flipping the car
moveMap.bindCmd(keyboard, "ctrl r", "commandToServer(\'resetCar\');", "");

//-----------------------------------------------------------------------------
#2
09/09/2007 (2:20 am)
Thanks, this works.