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