Can I modify X velocity in local space (addforce will also do)

I have an object. When the object hits a wall, I want to add a velocity to push it away. It’s kind of like pinball but something different. Anyway, I know about

transform.forward

but it moves it forward. I want it to move to the side. Here is a piece of my code:

void OnTriggerEnter(Collider c){
		if (c.transform.name == "right_guard" || c.transform.name == "left_guard") {
			switch (_self) {
			case "right":
				_car.rigidbody.velocity = new Vector3 (-_velocity, 0, 0);
				Debug.Log ("Collided right");
				break;
			case "left":
				_car.rigidbody.velocity = new Vector3 (_velocity, 0, 0);
				Debug.Log ("Collided left");
				break;
			case "front":
				_car.rigidbody.velocity = new Vector3 (0, 0, -_velocity);
				Debug.Log ("Collided front");
				break;
			case "back":
				_car.rigidbody.velocity = new Vector3 (0, 0, _velocity);
				Debug.Log ("Collided back");
				break;
			}
		}
	}

The object gets pushed around correctly, but in Global space. How can I make this into local?

Here is an image of my situation:

When the poor car faces the opposite direction, it gets pulled towards the wall resulting in a glitch (flying up and sometimes getting stuck in the wall) resolved by my creativity :3

Use Rigidbody.AddRelativeForce() instead of AddForce(), this will then use local space.

Alternatively, using your method of setting the velocity trough rigidbody.velocity, you could also use Transform.TransformDirection() to convert the local velocity to global velocity

You can use Transform.right for X axis. There’s also ‘up’ for Y axis.

And if you want opposite directions in local space you can multiply any of these by -1 (turns forward into backward etc.).