get player position in torque c++

There are no stupid questions, just stupid answers.
5 posts Page 1 of 1
subabrain
Posts: 126
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Mon Oct 02, 2017 8:29 pm
Hello Friends,

i tried to look for a Function to get the Position from the Player - i know the thing in Torquescript but i need it for the c++ code of Torque 3D.

would be nice if you could tell me :)

thx and gn8!
Robert
LoLJester
Posts: 38
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Mon Oct 02, 2017 11:39 pm
getPosition()
subabrain
Posts: 126
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Tue Oct 03, 2017 8:43 am
hi,

yes i tried this already - i think its from the player class?

So i tried this with included the player.h :( :

Player *pl = new Player();
Point3F pos = pl->getPosition();

but its not the active position it always goes to point 0.000 0.000 100.000 :/

maybe you know why?

thx and greetz!
Robert
irei1as
Posts: 72
Joined: Fri Feb 27, 2015 5:13 pm
by irei1as » Tue Oct 03, 2017 11:15 am
Ah, the Player class it isn't only for the active game player. It's just an object that moves like a Player and it can be used as the control object.
Maybe something like "actor" could have been more appropriate.

When you use "new" you create a new instance that is independent of any other Player object.
You are using getPosition() correctly but as you're using it in a new object you just get the initial value of the position as defined in Player::Player().

What you need is to first find the pointer of the player character and then use getPosition() on that.
For that you can use getControlObject with the GameConnection

Code: Select all

GameConnection* connection = GameConnection::getConnectionToServer();
if( !connection )
{
   //fail with the game. Maybe you haven't started the level. Return an error.
}
Player* playerObject = dynamic_cast< Player* >( connection->getControlObject() );
if( !playerObject)
{
   //fail. Maybe the control object is a camera or a vehicle not parented to Player
}
Point3F pos = playerObject->getPosition();


If you add that I think you may need as extra
#include "T3D/gameBase/gameConnection.h"
subabrain
Posts: 126
Joined: Sat Aug 20, 2016 4:58 pm
 
by subabrain » Tue Oct 03, 2017 1:09 pm
Hey irei1as,

thanks a lot for your help - it works perfect!

Greetings
Robert
5 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest