Jump to content

get player position in torque c++


Recommended Posts


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!


Link to comment
Share on other sites

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


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"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...