Teleport via Script
by Yonkey · in Torque Game Engine · 02/17/2005 (2:06 pm) · 10 replies
Hello,
I have been following this resource: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2930 but I want to be able to teleport via script instead of by triggers.
I have this in my server/scripts/commands.cs file:
this in my server/scripts/teleport.cs file:
and this is the line of code I am using in another script to call the teleport:
I get the error Unable to find object: '' attempting to call function 'getPosition', even though I am giving an %obj to the Teleport function. Can someone please tell me what I'm doing wrong?
Thanks
I have been following this resource: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2930 but I want to be able to teleport via script instead of by triggers.
I have this in my server/scripts/commands.cs file:
function serverCmdTeleportPlayer(%client, %targetObj)
{
%player = %client.player;
%currPlayerPos = %player.getPosition();
echo("CurrPlayerPos: " @ %currPlayerPos);
%targetPos = %targetObj.getPosition();
echo("TargetPos: " @ %targetPos);
%x = getWord(%targetPos, 0);
%y = getWord(%targetPos, 1);
%z = getWord(%targetPos, 2);
%z += 3.0;
%finalPos = %x SPC %y SPC %z;
%player.setTransform(%finalPos);
}this in my server/scripts/teleport.cs file:
function Teleport(%client, %target)
{
commandToServer('TeleportPlayer', %client, %target);
}
function getTeleportObject(%sphereName)
{
%dataGroup = "MissionGroup";
for(%i = 0; %i < %dataGroup.getCount(); %i++)
{
%obj = %dataGroup.getObject(%i);
if (isObject(%obj)) {
if(%obj.getClassName() !$= "SpawnSphere")
{
// no trigger!
continue;
}
if(%obj.getName() $= %sphereName)
{
echo(%obj.getName());
return %obj;
}
}
}
}and this is the line of code I am using in another script to call the teleport:
Teleport(%client.player, getTeleportObject("sphere"));I get the error Unable to find object: '' attempting to call function 'getPosition', even though I am giving an %obj to the Teleport function. Can someone please tell me what I'm doing wrong?
Thanks
#2
02/17/2005 (7:10 pm)
I still get the error in commands.cs: Unable to find object: '' attempting to call function 'getPosition'.
#3
Teleport(%client.player, getTeleportObject("sphere"));
use...
Teleport(getTeleportObject("sphere"));
02/18/2005 (4:09 am)
Instead ofTeleport(%client.player, getTeleportObject("sphere"));
use...
Teleport(getTeleportObject("sphere"));
#4
I don't even need to use the getTeleportObject function anymore because it now works with just Teleport("sphere"). :)
02/18/2005 (7:33 am)
Thanks guys! It works!I don't even need to use the getTeleportObject function anymore because it now works with just Teleport("sphere"). :)
#5
I used this to fix a problem with the respawn (Ctrl R) in the racing starter kit, when triggered torque crashes.
This seemed to be to do with the line that deleted the old car object. If commented out the rest would work.
So I have changed the serverCmdReset function to use setTransform to set the car back to its spawn.
To do this I also changed the createCar function to add a variable to the car object called spawnPoint that holds the spawn object ref.
I still need a bit of help though.
1) When the car moves to the spawn point it can be facing the wrong way in the world as it only seems to change the location of the object and not its orientation as well. How do I rotate the car to face the same way as the spawn point object.
2) The car will also keep its momentum when it moves to the spawn point and I need to stop it.
Anyone got any idea what the functions or methods are?.
Many thanks
08/10/2006 (1:33 pm)
Thanks all, this is great stuff.I used this to fix a problem with the respawn (Ctrl R) in the racing starter kit, when triggered torque crashes.
This seemed to be to do with the line that deleted the old car object. If commented out the rest would work.
So I have changed the serverCmdReset function to use setTransform to set the car back to its spawn.
To do this I also changed the createCar function to add a variable to the car object called spawnPoint that holds the spawn object ref.
I still need a bit of help though.
1) When the car moves to the spawn point it can be facing the wrong way in the world as it only seems to change the location of the object and not its orientation as well. How do I rotate the car to face the same way as the spawn point object.
2) The car will also keep its momentum when it moves to the spawn point and I need to stop it.
Anyone got any idea what the functions or methods are?.
Many thanks
#6
That will put the car alligned with the spawn point including the rotation and stop it dead there.
08/10/2006 (10:15 pm)
You need to get the transform of the spawn point. So something like.%trans = %spawnPoint.getTransForm();
%car.setTransfForm(%trans);
%car.setVelocity("0 0 0");That will put the car alligned with the spawn point including the rotation and stop it dead there.
#7
08/14/2006 (1:10 pm)
Ralph >>> Thanks for the help. I see where I was going wrong with setTransform now. And thanks again for the SetVelocity method aswell.
#8
However the setVelocity method doesn't work.
I tried
%client.car.setVelocity("0 0 0");
But no joy. No error.
So I tried using the getVelocity method of the spawn point as its set to "0 0 0" like so.
%client.car.setVelocity(%client.car.spawnPoint.getVelocity());
But that didn't work either.
Is there something I'm missing?. Why doesn't the setVelocity method of the car object do anything?.
Many thanks in advance.
08/14/2006 (3:36 pm)
Using the getTransform of the Spawn object worked fine.However the setVelocity method doesn't work.
I tried
%client.car.setVelocity("0 0 0");
But no joy. No error.
So I tried using the getVelocity method of the spawn point as its set to "0 0 0" like so.
%client.car.setVelocity(%client.car.spawnPoint.getVelocity());
But that didn't work either.
Is there something I'm missing?. Why doesn't the setVelocity method of the car object do anything?.
Many thanks in advance.
#9
This is beyond me.
Why can't I simply stop the vehicle and move it's location. Shouldn't this be simple?.
Am I overlooking something silly?.
08/14/2006 (8:48 pm)
I have found that there isn't a Vehicle::setVelocity mothod in Vehicle.cc and if you create your own, the information packets that are being sent to and from the server seems to start the vehicle moving again for a short while.This is beyond me.
Why can't I simply stop the vehicle and move it's location. Shouldn't this be simple?.
Am I overlooking something silly?.
#10
Full details posted here.
www.garagegames.com/mg/forums/result.thread.php?qt=49327
Many thanks to everyone who has helped.
:)
08/18/2006 (5:36 pm)
OK, so I decided to go back to the original code to respawn the car using Ctrl + R and have found a workaround. Its only a one liner but its in the engine code so you will need to have purchased Torque to fix the problem.Full details posted here.
www.garagegames.com/mg/forums/result.thread.php?qt=49327
Many thanks to everyone who has helped.
:)
Zod
function Teleport(%client, %target) { commandToServer('TeleportPlayer', %client, %target); } to be: function Teleport(%target) { commandToServer('TeleportPlayer', %target); }When the server gets that it automatically sets the first argument as the client..