I’m trying to request the gameObject name from the object hit by the raycast hit using the rigidbody.SweepTest function on my player, how would i do this?
what i’ve got currently:
RaycastHit hitLeft; //is the player gonna collide on the left?
rigidbody.SweepTest(-transform.right, out hitLeft, 0.1f);
RaycastHit hitRight; //is the player gonna collide on the right?
rigidbody.SweepTest(transform.right, out hitRight, 0.1f);
RaycastHit hitForward; //is the player gonna collide on the front?
rigidbody.SweepTest(transform.forward, out hitForward, 0.1f);
RaycastHit hitBack; //is the player gonna collide on the back?
rigidbody.SweepTest(-transform.forward, out hitBack, 0.1f);
if (Input.GetKey(KeyCode.A) && hitLeft.collider.gameObject.name != "Terrain") //left & right movement
transform.position += -transform.right * speed;
if (Input.GetKey(KeyCode.D) && hitRight.collider.gameObject.name != "Terrain")
transform.position += transform.right * speed;
if (Input.GetKey(KeyCode.W) && hitForward.collider.gameObject.name != "Terrain") //Forward & Backward movement
transform.position += transform.forward * speed;
if (Input.GetKey(KeyCode.S) && hitBack.collider.gameObject.name != "Terrain")
transform.position += -transform.forward * speed;