Make collision only affect rotation

Godot Version



I have a player character in the form of a tank with both a body and a gun turret. The body is controlled with the keyboard while the turret always tries to face the mouse, however I’d like to make it possible to collide with walls and stop. I’ve tried to implement this, but no matter how I try to handle it, the collisions always end up pushing the turret and displacing it on the tank body. Is there some way to lock the position of the turret and force it to handle collisions only with rotation, or simply snap it to the last rotation that doesn’t clip the wall?

I don’t understand everything but I think the turret is always following your mouse, and when it hits a wall it still pushes onto it to keep on following the mouse? If that is the case then you probably need to add a condition in your script where you move the turret to the mouse, make it follow the mouse only if it isn’t colliding with anything (but this probably won’t let you move it away from the wall after collision)

This doesn’t work, the collision handling will leave the turret where it is even if the tank body moves elsewhere. I need a way to handle collisions such that the turret will spin out of the way without its origin moving from where it’s set on the tank.

Have you tried a HingeJoint3D?

It may be helpful to post your code movement and the turret aiming, as well as a screen shot of your node hierarchy.

My first thought is to have your turret seperate to your tank body, and have its global position link to a marker 2D on your tank body, like a hard point. Then it’s position should be locked to that point. The turret should continue looking at the mouse even if the tank is breakdancing from a collision.