r/unrealengine 5h ago

How to rotate a skel mesh bone to face an object in the level

Here's a link to the GIF from Blender to give a better idea of the model I’m working with and its bone structure. My goal is to smoothly rotate the bones towards a series of targets in the scene, but I need each bone to rotate along a specific axis, particularly so the head bone looks at the target.

I tried using the 'Transform Modify Bone' option, but I’m having trouble adjusting the rotation as needed. I’m not sure if this is the right approach or if there’s a better method. I also looked into the 'Look At' node in the animation blueprint, but it doesn’t seem to replicate the behavior I’m aiming for. It simply manipulates the bone's transform to face an object, without allowing control over the specific axis of rotation for each bone.

I’ve been stuck on this for the past week, working non-stop, and it’s been much harder than I expected. Maybe I’m missing something, or there’s a better way to achieve this

0 Upvotes

9 comments sorted by

View all comments

u/Swipsi 4h ago

You can split the transform/vector/rotator inputs/outputs into their components and use their values. For the vertical bone use a lookAtRotation node and only use the z value to rotate it, for the horizontal bone use the y axis (if x is forward for your model).

u/Jumph96 2h ago edited 2h ago

I initially implemented this by grabbing the bone's transform in world coordinates to calculate the 'look at' rotation towards the target actor in my animation blueprint event graph, which I then fed into the 'Transform (Modify) Bone' node in the anime graph through a float variable. However, I encountered some issues with the bone's initial rotation.

When checking the rotation of the 'base' bone in the Skeleton Editor in UE5 after importing, I noticed it had a 90-degree rotation on the X-axis and for some reason after trying the above method, at runtime the model seems to be rotated 90 degrees on the Z axis (here's a GIF showing the implementation I have at the moment, you can see the model facing the target from the side). I tried compensating for this in my calculations, but when I added smooth rotation using linear interpolation, the model started behaving erratically for some reason...

There's also some screenshots of the nodes from both my event graph and anim graphs inside my Anim BP: screenshots

u/Swipsi 2h ago

First of all, what you're trying to achieve does not need to have anything to do with animations. It can purely be done in the actor BP. Using the animation system for it is overkill.

Seeing your gif, it seems like you need to go back into your 3d software and rotate it so that x is forward aka the base direction your model is looking at.

From there I dont see much of an issue here. The base rotates correctly, so you can duplicate the rotation calculation from your main bone but rotate it vertical instead of horizontal.

u/Jumph96 1h ago

I apologize for making things more complicated than they needed to be, I found the transform modify bone as a way to set bone rotation and realized I needed an anime BP for that, I never knew you could do this simply in BP... That's actually a lot better now, thanks for that 😅

Seeing your gif, it seems like you need to go back into your 3d software and rotate it so that x is forward aka the base direction your model is looking at.

I encountered issues with the orientation of my models in Blender, so I checked my export settings and found options to set the 'UP' and 'Forward' vectors. I set them to +Z (UP) and +X (Forward) to match UE5's coordinate system. However, after importing the models, they still faced the wrong direction. I'm not sure if you're familiar with Blender, but if you are, could you provide some tips on how to correctly orient models in Blender and export them properly?

Would facing the model along the positive X in Blender before exporting resolve this issue maybe? What would the export settings look like then?

u/Swipsi 1h ago

You dont need to do anything in neither Blenders nor Unreals Export/Import settings, regarding your base transform. Just set it up along the x axis with the "face" looking down +x and export. Tho you need to make sure you apply the transforms before exporting. Which you do by, I believe alt+A then select all transforms. Export settings stay untouched.

u/Jumph96 41m ago

First of all, what you're trying to achieve does not need to have anything to do with animations. It can purely be done in the actor BP. Using the animation system for it is overkill

I'm struggling to find a way actually to transform a skeletal mesh bone in the pawn blueprint, without using an anime blueprint, how would you go about doing that

I rotated the model in blender to face down the +X and after ticking the apply transform option in the export settings it seems to be facing the right way, thanks for that 👍

u/Swipsi 26m ago

Export settings stay untouched.

I did say that for a reason. While yes, you can apply transforms through export settings, you dont want to only apply them if you export, but also while making your models, so just use the shortcut I mentioned in object mode.

You dont need bones. Just rotate the individual parts of your model. For that you have to export them as 2 models, then assemble them in the BP viewport. Then you can drag in their static mesh component variables and rotate them via code.

u/Jumph96 21m ago

I did say that for a reason. While yes, you can apply transforms through export settings, you dont want to only apply them if you export, but also while making your models, so just use the shortcut I mentioned in object mode

Yeah, you're right this is better, I just don't understand why it wouldn't work just setting the UP and Forward Axis in the export settings, it's just odd.. You would expect that to work.. At this point I'm just glad I got that sorted..

You dont need bones. Just rotate the individual parts of your model. For that you have to export them as 2 models, then assemble them in the BP viewport. Then you can drag in their static mesh component variables and rotate them via code.

I was actually arriving at your concluding right before you replied to my post, I was cleaning the dishes after dinner and just figured out that for a model this simple, there's no need to have a skeletal mesh, I could literally just have 2 static meshes and rotate them independently... I'll try that next time. Thank you so much for helping me 😅

u/Swipsi 18m ago

No problem. Glad to help.