Reflecting Objects off of Boundaries/Walls

Hi

I’ve got walls around my game area designed to keep my hazards in the game. However, the hazards hit the wall and either stop or slide along the wall never been reflected back into the map. The hazard has a rigidbody component (gravity disabled), and a capsule collider. It is always moving on the x and z axis.

I can’t think of the best way to do it, I’ve looked at this forum which makes sense but I haven’t been able to convert it into C# partly because I’ve been trying to work out how to make it work with my code. Otherwise I have no idea how to do it.

If anyone has any ideas to how this can be done I would be very appreciative.

The code I’m using to make it move around randomly.

void Start()
{
        //random rotator
		rigidbody.angularVelocity = Random.insideUnitSphere * tumble;

		//movement
		Vector3 randomDirection = new Vector3(Random.Range(-1, 2), 0.0f, Random.Range(-1, 2));
		rigidbody.velocity = randomDirection * speed;
}

EDIT
I’m trying to get this sort of effect. Right at the beginning of this video you see the cubes hit the boundary and effortlessly without fail bounce of it back into the game area. Let's Look | Sixty Second Shooter Prime - YouTube

I have messed with settings in the Bouncy Physics Material and they do seem to bounce off of the boundary but they tend to still get collected and stuck on the wall and in the corners.

if you want proper physics, use AddForce, instead of changing velocity

EDIT example

	private Vector3 randomDirection;
	public float force = 20.0f;
	
	void Start () {
		randomDirection = new Vector3(Random.Range(-1.0f, 1.0f), 0, Random.Range(-1.0f, 1.0f));

		//Drag is how fast object slowing down 
		rigidbody.drag = 0;

		//ForceMode.VelocityChange will ignore mass of object and apply velocity instantly
		rigidbody.AddForce(randomDirection * force, ForceMode.VelocityChange);
	}

use a physic material there is a standard(import package > physic materials ) one called bouncy. i used that one for my pinball.