Help with this rotation?

So everything always seems to be moving ahead nicely until I have to play with vectors and other complex math stuff. It reminds me I’m an artist by trade, not a programmer lol.

I have a prototype tank that aims at a wherever the mouse is on my terrain using the Smooth Look At Direction action. This works nicely.

The problem I have is with the rotation of the turret on slopes. I just want the tank to rotate its turret around its local Y axis.

Hopefully these pics will detail it better:


This shows the problem. The turret clips through the tank when trying to rotate on slopes, this happens wether or not I am holding the turret’s Y rotation.

This is what it should look like, regardless of angle of slope or position of the mouse. The turret only rotates around it’s local Y axis:

I know the answer lies in some vector equation that completely eludes me…

How do I use the Smooth Look actions yet keep the rotation only on the local Y axis…?? sorry If I haven’t explained well.

Is this done with play maker? I’m not familiar with the tool, but maybe you can lock the local x and z rotation with LateUpdate function in the turret object. Like this:

function LateUpdate() {
    transform.localEulerAngles = Vector3(0.0, transform.localEulerAngles.y, 0.0);
}

Thanks Potaski, yes I am using Playmaker for some actions, but also some in script.

I will try your suggestion, this problem has been doing my head in for the last 3 days!

Cheers