how to round vector3 to a grid position?
so i need to find the position off of the player object, snapped to a grid. i tried this code: public Vector3 GetPlayerPos() { var playerPos = player.transform.position / (150); playerPos = new Vector3(Mathf.Round(playerPos.x), Mathf.Round(playerPos.y), Mathf.Round(playerPos.z)); return playerPos * (150); }
but this always returns a 0,0,0 vector. the player object is defined and i have the right "using" stuff for mathf. any idea why? anyone has done this before? ideas on fixing it?
Answer by Symons · Sep 10, 2017 at 12:33 AM
I believe it's because you're declaring that vector3 playerpos is the players position but then you are saying that playerpos is now a new vector3 but you're trying to use it's previous data. Maybe just rename the second one to playerposgrid or something and I believe it should work.
Your answer
![](https://koobas.hobune.stream/wayback/20220612134507im_/https://answers.unity.com/themes/thub/images/avi.jpg)