Transform.position returns strange position
I'm working on a script that should spawn an NPC on the porch of a house that will be Instantiated by the player during runtime.
This is the position of the porch (Named SpawnSpot) which is a child of the house.
When i try to Get SpawnSpot.transform.position it always returns in every instance: 285.2, 0.6, 209.1; instead of its real position in this instance: 314.5, 1.24, 210.5
Answer by UnityCoach · Jun 16, 2017 at 03:34 PM
What you see in the editor is the local position.
transform.position
is the world position.
You can use transform.localPosition
instead.
Though, for instantiation you usually want to use world position.
doing transform.localposition returns -6.1, 1.2, 6.3 which is the offset spawnspot has from the position of the house, doing house.transform.position return 0,0,0 as it is not a child
no matter where the player places the building it always spawns the npc @ 285.2, 0.6, 209.1
Your answer
Follow this Question
Related Questions
If statement executes, even when its false again 2 Answers
Why is unity so bad at accuracy for something as simple as whole number coordinates. 1 Answer
Animator Position VS Script Vector 3 0 Answers
Hey Guys How to make a script 'private Transform Waypoint;, 0 Answers
My script is working just one time 1 Answer