Game Development Community

Wierd Respawning Issue

by Robert Fritzen · in Torque Game Engine Advanced · 03/14/2011 (11:19 am) · 1 replies

Hello, I'm currently working on a project that features tank combat, and so far it's running along fine, but now one bug has come up, and I have no idea what's causing it.

When a round starts, the tank spawns and everything is good, you can fire, move the tank and rotate the turret just fine. However, once you die, and try to respawn, the player object that controls the tank spawns, and a tank object spawns, but you can only rotate the player, without having any action on the tank but firing, this is my respawn code:

function GameConnection::spawnPlayer(%this) {
   // Combination create player and drop him somewhere
   if(isObject(%this.tank) || isObject(%this.player)) {
      return;
   }
   if(isSet(%this.respawnAllowance)) {
      if(%this.respawnAllowance > getSimTime()) {
         %this.tank = 0;
         %this.player = 0;
      
         messageClient(%this, 'msgClient', "c3GAME: Currently in respawn delay, please wait...");
         return;
      }
   }
   %spawnPoint = PickSpawnPoint();
   %this.createPlayer(%spawnPoint);
} 

function GameConnection::createPlayer(%this, %spawnPoint) {
   // CREATE TANK
   //Did the client F* up?
   if(%this.TankName $= "") {
      %this.TankName = "Celtic";
   }
   
   %tank = CreatePlayerTank(%this, %spawnPoint);

   %this.camera.setTransform(vectorAdd(%tank.getForwardVector(), "0 0 2"));
   
   //Freeze em!
   if(Game.InInitialPause) {
      %tank.setMoveState(true);
      %this.camera.setMode("TankObs", %this.tank);
      %this.setControlObject(%this.camera);
   }
   
   %this.currentWeaponSlot = 1;
   commandToClient(%this, 'DisableNTMM');
}

function CreatePlayerTank(%client, %spawnPoint) {
   %tankName = %client.TankName;
   if(%tankName $= "") {        //last minute check here
      %tankName = "Celtic";
   }
   %tank = $Tank::NameToBlock[""@%tankName@""].create(); //Handles creation of tank/turret
   MissionCleanup.add(%tank);

   %client.tank = %tank;
   %tank.cl = %client;
   %tank.client = %client;
   %tank.team = %client.team;

   %tank.setTransform(vectorAdd(%spawnPoint, "0 0 2"));

   %player = new Player() {
      datablock = PlayerBody;
   };
   %client.setControlObject(%player);
   %tank.mountedTurret.schedule(100, "MountObject", %player, 1);
   MissionCleanup.add(%player);

   %client.player = %player;
   return %tank;
}

#1
03/18/2011 (2:23 pm)
Figured it out, apparently the initial spawn was controlled by a different script, so I just mirrored my respawn to the working one, and it worked fine.