Mech Looking Mechanics

Godot Version

4.2.1.stable.official

Question

Hello,

Current implementation:

I have sperate head and legs nodes. The leg node drives the direction the mech moves and the head looks around. I also have a seperate “motor” node that handles acceleration of the mech relative to the direction the mech’s legs are facing.

Currently, I am using the roation_degrees of the head node on the Y axis along with the mouse position to turn the head of the mech. I am then clamping the view angle to a set value.

The Issue:

The above works great, until I include the rotation of the legs. When I turn the mech the camera stays fixed with the clamped view angle. This means that the player will not be able to turn the mech’s head to face the direction they are moving.

Resolution:

I’m looking for a way to “rotate” the heads clamp value to match the legs rotation. Meaning that if the head is rotated fully left, and the player turns their legs fully left the head can turn left again.

Attempted Fixes:

A fix that has gotten my part way there, but with some snapping of the view, is by adding the legs rotation to the heads clamp value.

This has gotten me some of the way there, however, there are visual bugs the occure when reaching the full rotation of the legs. When this happens the head will snap to specific angle.

I have also attempted to nest the head with the legs, this only turns the head of the mech with the legs. Not something I want as I like the feeling of a locked head postion until the player reaches a particular angle.

(I hope this makes sense. I have attempted to explain this is as fully as possible. I am happy to answer any questions and provide any code/screenshots/video needed to support.)

(This is also my first time posting, if something is missing from my post, please let me know and I will amend where I can.)