- Home /
Get Vector3 position of player?
Hi,
I have a first person controller on my scene named "Player". In my script I am trying to get the position of the player in Vector3. How exactly do I do this?
This is what I tried:
var playerObject = GameObject.Find("Player");
var playerPos:Vector3 = playerObject;
Debug.Log(playerPos);
This will give me an error: Cannot convert 'UnityEngine.GameObject' to 'UnityEngine.Vector3'.
Answer by Demigiant · Dec 11, 2012 at 10:42 PM
var playerPos:Vector3 = playerObject.transform.position;
is there a way to store the positions( after regular time intervals) in a separate log file for later use?
Hmmm How come the playerObject gives me an error: BCE0005: $$anonymous$$ identifier: 'playerObject'. ? Be
playerObject is the name he chose for his player object. You need to change that to whatever you've chosen to name your player.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085311im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
NullReferenceException in follow function 0 Answers
Move instantiated object towards player's posistion 3 Answers
Trying to make a simple inventory: 0 Answers
Need help with building system 1 Answer