Find Look at Rotation for Child Actor Turret

Hi,

tl;dr: I’m working on a Turret Blueprint for a small space-sim, the turret itself is a child actor attached to the spaceships blueprint. While the turret only needs to align its Base and Barrel on a horizontal and vertical axis itself respectively, it needs to do so in regards to the ships X,Y,Z rotation as that can rotate freely.
The turret itself is supposed to rotate towards a target vector, which is the result of a line trace run from the mouse’ position. So basically, it just has to align towards whatever I point the cursor at.

I’ve already looked through all of the topics on this I could find, both here and on other sites but haven’t been able to find a solution that works for my case.

To give a bit more detail on how it’s currently set up:


This is the Skeletal Mesh of the Turret I’m using to test the setup. The idea was to run a “Find Look at Rotation” function from both of the highlighted bones, since they’re not on the same position (depending on the turret mesh) and might need to rotate differently.

To assist with getting the correct rotation, I’ve also recently added two helper objects in the Blueprint at both the BaseSocketPoint and TurretSwivelPoint, which are rotated to give the proper Up and Forward vector since the bones are rotated differently.

I’ve already tried a good amount of different approaches, which would be too much to include here, especially since the blueprint has gotten extremely messy at this point. I’ve made attempts with both altering the animation of the Skeletal mesh as well as setting the bone rotation directly with a poseable mesh. Both have resulted in either an incorrect rotation or the mesh just rotating around endlessly.

I’d be grateful for any suggestions and tips on this.

Since you are using bones, I think that what you need is a control rig, once you set it up you just have to pass a Vector to the turrets and they will all point to that point.

There is also an example project by Epic that contains a giant turret with legs (if you need ispiration).

Thank you, that seems to have finally done the trick. With the new setup the Turrets now align perfectly to the Target Vector after I translated it into their Transform.


Only issue left is that I can’t seem to find a way to easily constrain their rotation to specific angles. Currently the Barrel, for example, can do pretty much a 180° rotation to both directions. How would I prevent that?
The Rotation Constraint only seems to let me constrain it on entire axis, which is still useful, just not what I’m looking for.
Also, is there a way to smoothly transition the change in rotation? Currently I’m using the VInterp node to interpolate the turret internal variable for the target up to the global target Vector, but maybe there’s a better way?

You can add constraints in the Physics Assets tab. If you don’t have any bodies, in the Tools panel, ensure Create Constraints is checked and Create Body for all bones. Then right click on the root body and regenerate bodies. Then if you click on the parent bone, there might be a constraint with it’s child bones in the Graph. If so, click on the constraint and set the constraint. If the constraint doesn’t exist, you’ll have to right click the parent body and add the constraint to the child bone.

This is an older video, but should still apply.