I have an object in front of my character which is a cube - it moves with the player and rotates on y axis when ‘q’ and ‘e’ buttons are pushed. I need to find x and z values of this cube’s corners (doesn’t matter if it’s the bottom set or one on the top.)
I tried making Vector3 type variables and setting their values to (cube.transform.position.x - cube.transform.localscale.x / 2) same for z (pluses and minuses change depending on the corner), but that didn’t work when the cube was being rotated - I used gizmos to check them. Is there any easy way to solve this?
cube.transform.localScale / 2 will indeed get you the local position of one of the cube’s corners; Vector3.Scale(cube.transform.localScale / 2, new Vector3(1,1,-1)) will get you one of the others (different combinations of 1 and -1 there will get you all eight). Then, to find them in world space, use cube.transform.TransformPoint().
It worked thanks - but I’ve got another problem. When I set cube’s scale in Start() cube.transform.localScale = new Vector3(2, 1, 1); something weird happens. Here’s the pic
, seems like whenever the scale value isn’t equal to 1 it adds to the position of the point somehow.
using bounds.min and bounds.max should get you two flavors of the cube’s corners, and taking various values from the min and max’s x,y,z coords should get you the other six.