How To Rotate My Tank Turret Around Local Z Axis?

It looks like you have the correct component hierarchy, which is the most important thing.

The only thing you should be doing is changing the relative rotation on the turret with respect to the body ( because that’s how they move ), in Z.

If you stick with that, you won’t get this tilting I see.

The problem remains ( as I’m sure you know ), that using ‘set relative rotation’, will glitch when it gets to 180. There are two ways around this

  1. ONLY use these nodes :slight_smile:

‘set relative rotation’
‘combine rotators’ ( NOTE, it does matter which order you put the rotators in )
‘delta rotator’

You basically use the two rotator nodes to calculate what position you’re going to set the turret to next, and then use the ‘set relative rotation’ node to do that. This will be with a timeline. The reason we use those nodes is, because internally, they use quaternions which avoid the 180 snapping problem.

  1. Use ‘add relative rotation’. DON’T use a timeline with this node. If you think about it, you’re adding rotation every frame, it’s no wonder it spins. If you want to use this node, you need to do it with finterp.

Here, the player would choose ‘rotate right’ ( for instance ), and you decide you’re going to add 30 degrees to the turret rotation, and use ‘add local rotation’ with an finterp on tick. It’s a very different method from above. It depends on how you want to setup the movement.

With this option, if you bothered to print out the Z rotation, it would be doing crazy things at 180, but we don’t care, because we’re only dealing with relative changes.

Does this make some sense?

1 Like