Player Position
by Howard Dortch · in Torque Game Engine · 05/22/2004 (5:52 am) · 29 replies
How would I retreive the player current position on the landscape?
I looked in the player.cc file and see pos but it's private and I dont see a function to call the data.
I looked in the player.cc file and see pos but it's private and I dont see a function to call the data.
#22
When you issue an exec( "path/file.cs" ) command, it will check first if file.cs.dso exists and is up to date, if it doesn't, it will compile file.cs.
What might be happening is that file.cs isn't compiling if it has an error. Something that happens is that file.cs.dso exists but the file.cs doesn't compile. so it will run the older version.
05/25/2004 (1:32 pm)
Well, the objective of this test was to see if the player position shows up in the console or if you have a problem somewhere else.When you issue an exec( "path/file.cs" ) command, it will check first if file.cs.dso exists and is up to date, if it doesn't, it will compile file.cs.
What might be happening is that file.cs isn't compiling if it has an error. Something that happens is that file.cs.dso exists but the file.cs doesn't compile. so it will run the older version.
#23
This works, I type metrics(pos); in the console and it prints on the display
function playerposMetricsCallback()
return "HELLO TORQUE";
}
So I assume this is wrong
function playerposMetricsCallback()
{
%ppos = $player.getTransform();
%x = getWord(%ppos, 0);
%y = getWord(%ppos, 1);
%z = getWord(%ppos, 2);
return " POSITION: x=" @ %x @ " y=" @ %y @ " z=" @ %z;
}
game.cs file has this after I spawn the player
$player = %this.player;
05/25/2004 (3:04 pm)
Ah then that was the problem. Probably should be more obvious if a file wont compile.This works, I type metrics(pos); in the console and it prints on the display
function playerposMetricsCallback()
return "HELLO TORQUE";
}
So I assume this is wrong
function playerposMetricsCallback()
{
%ppos = $player.getTransform();
%x = getWord(%ppos, 0);
%y = getWord(%ppos, 1);
%z = getWord(%ppos, 2);
return " POSITION: x=" @ %x @ " y=" @ %y @ " z=" @ %z;
}
game.cs file has this after I spawn the player
$player = %this.player;
#24
Add the following to game.cc
Add the following to Metrics.cs
add the following to the metric switch statement in the same file
start your client and server, turn it on from the console using metric("loc");
close console, and you will see loc in upper left of screen.
Note: The solutions that are above mine, will work, only if your running client and server as one. But I expect Howard is running them seperate.
05/25/2004 (3:19 pm)
This will give you the client side location of the control object, which in most cases is the player, or vehicle, or what notAdd the following to game.cc
ConsoleFunction( getControlObjectLocation, const char*, 1, 1, "Get Location of controlled object.")
{
GameConnection* connection = GameConnection::getServerConnection();
if (connection)
{
ShapeBase* pSB = connection->getControlObject();
if (pSB != NULL && pSB->isClientObject()) {
Point3F vel = pSB->getPosition();
char* retBuf = Con::getReturnBuffer(128);
dSprintf(retBuf, 128, "%g %g %g", vel.x, vel.y, vel.z);
return retBuf;
}
}
return "0";
}Add the following to Metrics.cs
function locMetricsCallback()
{
// position echo
%loc = getControlObjectLocation();
%pos_x = getWords(%loc, 0, 0);
%pos_y = getWords(%loc, 1, 1);
%pos_z = getWords(%loc, 2, 2);
return " Location X = " @ %pos_x @ " Y = " @ %pos_y @ " Z = " @ %pos_z;
}add the following to the metric switch statement in the same file
case "loc": %cb = "locMetricsCallback()";
start your client and server, turn it on from the console using metric("loc");
close console, and you will see loc in upper left of screen.
Note: The solutions that are above mine, will work, only if your running client and server as one. But I expect Howard is running them seperate.
#25
I would like to thank you all for your time, I'm really sorry I suck at this and I dont mean to be a pest. I have programmed almost every processor in many languages over 25 years and I was cut down by a script file. Oh the pain!
05/25/2004 (3:24 pm)
Ok I found the bug. Apparently using $player is a no no so I changed it to $PlayerLocator and now it works. Whew! 23 posts and 3 days later! I would like to thank you all for your time, I'm really sorry I suck at this and I dont mean to be a pest. I have programmed almost every processor in many languages over 25 years and I was cut down by a script file. Oh the pain!
#26
09/21/2004 (10:24 pm)
If you store this as a global what effect does that have when you want to do multiplayer with bots (and your bots use $PlayerLocator for the player handle).....???
#27
$myPlayer is me the client.
$bots[#] are the bots; every time a new bot is spawned I have a counter that counts up and I save that bot into the array.
I have a seperate create player for the bots and for the client. In the onAdd block is where I create the global.
Marrion
09/22/2004 (2:52 am)
Then the bot will overwrite the $PlayerLocator. This is what I do for our game.$myPlayer is me the client.
$bots[#] are the bots; every time a new bot is spawned I have a counter that counts up and I save that bot into the array.
I have a seperate create player for the bots and for the client. In the onAdd block is where I create the global.
Marrion
#28
09/22/2004 (8:58 am)
Well wouldn't you have to create an array for $myPlayer if you wanted to do multiplayer games??
#29
09/23/2004 (6:54 am)
Yes you would. Our game project is a single player only game.
Torque 3D Owner Howard Dortch
Default Studio Name
I changed it back and all it will do now is print HELLO. I assume since I changed the metrics.cs file that the metrics.dso file would be recompiled but I guess not. If I remove the metrics.dso from the directory it wont work at all. How do the dso files get compiled in the first place? I assume the engine looks for a dso on startup and failing that it looks for a cs file with the same name and compiles it or do I have that all wrong?
geez this is depressing.
I can't believe the devs didn't have a simple print to screen function in the engine.