Can I get the relative transform of a specific bone mid animation?

Just as some backstory, I’m rather new to the whole world of Unreal and I have been rather stumped with the logic behind animating. I have been taking Udemy classes as well as watching videos to try reverse engineering code and just learning the ropes of it all.

So I am currently developing a topdown strategy game. The camera is attached with a spring arm to the player’s pawn and the player can only adjust yaw with Q and E keys.

I have been trying to get a function where whenever you hold right mouse click the tank turret will orient its yaw and the pitch of the gun to the proper angles and also continue to try holding those angles to its best of ability (I was hoping to use interpolate so the turret moves slow) as long as right mouse click is held. But in my pervious attempts the whole turret readjusts its orientation whenever I press Q or E and it seems to strictly base its transform on that of the base pawn and camera, and not the socket I had added for the turret in the Skeletal Mesh.

I have setup proper armatures for the Gun, Turret, and chassis of the tank. I have working animated wheels and suspension. But I just cannot get the turret to work as intended. Can I not gather updated orientation/vector of a specific socket or bone with every update instance? It seems to only gather the pawn and player controller’s. Also note, the whole pawn is all one static mesh. I was in the process of making the tank three separate meshes all children in sequential order (chassis, turret, gun) but I wanted to make sure if my previous way was possible and I was just missing something.

Here is a photo example of how my project looks for context:

as well as my code (without input code since I figure that isn’t needed):


Thanks in advance, maybe I could regain some sanity by fixing this lol. If not its back to the drawing board.

  • Testpilot

Yup you’re trying to directly control a bone, which can be finicky.

but, there’s a way to do this by making the turret a separate static mesh and setting it up as a child component of your tank pawn. This would let you directly manipulate its rotation without affecting the entire pawn or messing with skeletal animation.

  1. Separate the Meshes: If you haven’t already, separate your tank into three different meshes: the base, turret, and gun. Import these into Unreal.

  2. Set up the Blueprint: In your tank’s Blueprint, set up your turret and gun as separate Static Mesh Components, parenting them appropriately. For example, the gun should be a child of the turret, and the turret should be a child of the base. This way, rotating the turret won’t affect the base, and rotating the gun won’t affect the turret.

  3. Adjust the Turret Rotation: To get your turret to aim where your mouse is pointing, you’ll need to do a little bit of math:

  • You gotta know where your partner is, right? So get the World Location of your turret and the World Location of the mouse cursor (the PlayerController can help you with that with its DeprojectScreenPositionToWorld function).
  • Subtract the turret’s location from the mouse’s location to get a direction vector.
  • Use this direction vector to calculate the rotation your turret needs to face this direction. You can use the FVector::Rotation function for this.
  • Apply this rotation to your turret using the SetWorldRotation function. You could use the FMath::RInterpTo function to smoothly interpolate to this rotation over time.
  1. Consider Player Input: To ensure the turret only moves when the right mouse button is held down, you’ll want to wrap the above logic in an If statement that checks if the right mouse button is being held down. You can use the IsInputKeyDown function on the PlayerController for this.

Hit me up if you need more help, alright?

Thank you for the quick reply! I greatly appreciate it. I will get to work on separating the meshes and update soon if I run into problems.

So it took me a couple of days to get around to attempting at this fix. I made some headway and did what you said successfully. Though it seems that the cursor point is set immediately at the simulation start and the turret will only lock onto that specific point and will continue to update at every tick. No matter where I move or the the obstacles I drive over. I decided to skip past the input event until I can get this working continuously during simulation.
Here is my code for rotating the turret:

Here is the tank driving over an obstacle:

GameTest1 - Unreal Editor (gyazo.com)

Is there a way to get the turret and barrel to simulate when driving over obstacles? I don’t like how the turret maintains it place as if it is hovering on the tanks body, and not connected. :frowning: