subabrain Posted October 2, 2017 Share Posted October 2, 2017 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 Quote Link to comment Share on other sites More sharing options...
LoLJester Posted October 2, 2017 Share Posted October 2, 2017 getPosition() Quote Link to comment Share on other sites More sharing options...
subabrain Posted October 3, 2017 Author Share Posted October 3, 2017 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 Quote Link to comment Share on other sites More sharing options...
irei1as Posted October 3, 2017 Share Posted October 3, 2017 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" Quote Link to comment Share on other sites More sharing options...
subabrain Posted October 3, 2017 Author Share Posted October 3, 2017 Hey irei1as,thanks a lot for your help - it works perfect!GreetingsRobert Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.