2D Tank game problem

Hello :smile:
I started to make a 2D tank game and got a problem with the physics of the tank. In the script I move the tank with rigidbody2d.velocity = (Vector2)transform.TransformDirection(Vector3.up) * speed;. When the tank hits a wall diagonally I want the tank to stop but instead the tank rotates… to explain better what I mean I got 2 images.

2204221--146436--problem1.jpg
This is what I want to happen when I press the forward key…

2204221--146437--problem2.jpg
This is what actually happens.

I already tried to attach a 2D physics material to the collider of the tank and changed the values but it didn’t work :frowning:
I hope that somebody can help me :slight_smile:
And sorry for my english^^… I am from germany

You could attempt to create an OnDetect() method that detects when you’ve hit the wall, and then based on that create a boolean. This boolean affects whether or not your velocity keeps on updating, and if you’ve hit the wall it immediately zeroes the velocity. I’ve not much experienced with colliders as of yet, so I’m not entirely sure if that is in fact possible, but I have faith in the creators of Unity that they’ve left colliders open-ended. If not, you could try creating your own system of colliders, but that seems like an extensive amount of work. Hopefully this helped!

1 Like

Hey thank you man :smile: you really helped me.

No problem! Tell me how it goes!