How to make an object without gravity bounce off colliders like it's in space?

I’m spawning cars with colliders. As soon as the player loses, the trigger on the car’s collider is turned off and it starts colliding with other cars/walls.

My problem is after it reaches the left/right end of the screen where I placed a wall with a collider, it gets stuck. I wanted it to bounce off to a random direction and rotate to make it look like it’s in space.

I have this code on my car object:

void Update()
{
   if (GameManager.SharedInstance.GameOver)
   {
      col.isTrigger = false;
   }
}

void FixedUpdate()
{
   rb.velocity = new Vector2(speed, 0);
   //for cars going to the left, I set it to --> rb.velocity = new Vector2(-speed, 0)
}

I also learned that all physics should be placed on FixedUpdate, any idea on how to do this? Any help would be appreciated! Thank you!

Hi,

I would use an OnCollisionEnter() method on the wall / outer boundary, then detect the layer or tag of the object colliding with it. If the layer / tag is “car” then aplly a force to the rigidbody of the colliding object.

For example.

Set the tag of each car object to “Car”.

On the wall / bounary add a script (or add to an existing script) containing something like…

void OnCollisionEnter(Collision col)
{
    if(col.Tag == "Car")
	{
		//Add force to the col rigidbody
	}
}