I have a movement script that attemps to set freezeRotation to true, set y = 0 on the transform position, locked rotation and position of y on the rigidbody, etc…
I have a top down shooter that has a huge boundary of 4 cubes, elongated to bet a square space. The ship can fly anywhere inside and I want to bounce off the walls (or stop at this point) when the ships colliders hits the walls collider. No matter what script or setting I do, the y value (which should always be 0) starts changed after impact. Is there a way to force this to 0 at all times.
this causes the bounce:
GetComponent<Rigidbody>().freezeRotation = true;
GetComponent<Rigidbody>().velocity = Vector3.Reflect(GetComponent<Rigidbody>().velocity, collision.contacts[0].normal);
and these are my attempts and fixing y to 0:
var position = transform.position;
transform.position = new Vector3(position.x, 0, position.z);
transform.localRotation = Quaternion.identity;