How to make a tank barrel collide?

Godot Version

4.3

Question

I have a simple tank using a characterbody3d a turret and a barrel that moves with the mouse with a simple fps script.
How can I make the barrel collide like the capsule on the characterbody3d

If the barrel collides with I wall I want it to stop the tank, and if the barrel rotates to a wall it should stop the rotation, how can I achieve this?

The way that work half way, was to put the barrel collider as child of the characterbody3d, but when I rotate the turret and there is a wall the tank rotates around it. And is more difficult code the rotation of the barrel if it is the child of the characterbody3d.

Hmm, that’s a tough one. Maybe you could detect if the barrel has collided and tell the main tank body to stop trying to rotate?

1 Like