Hi, I'm trying to instantiate bullets from weapon script. I have empty object (weapon child) that is a bullet spawn point, and weapon has it's link. Everything works perfect, except transform.position and transform.LocalPosition returns the same local coordinates. I found out that seems like accessing position of a child from another child gives this result, which is my case as weapon is a child of a Player. However accessing bulletSpawnPoint position from Player gives the same result (I'm getting it through code as the weapon is created object). The question is if there are any ways to get global position in my case, or I need modify my hierarchy? Thank you. images of a code and game scene
image description image description image description
UPDATE
Figured out that the same code returns different values in Update and public function Shoot. Also if I call Shoot() from update it works fine, but if I call Shoot() from Player script it returns wrong position (probably taken from prefab). Any suggestions?
Volodymyr Hryhoriev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
So, there is no problem with transform position. The problem was I was getting component from prefab itself, when I changed it to the created instance everything works. Here is a screenshot where was the mistake:
image
Volodymyr Hryhoriev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.