FRotator off by 90 or wrong axis?
I am taking an example from a diffrent project and re-creating it in my own game. In the original working project, there is a gun that rotates around the hand correctly and these are some of the correct rotation values:
In my own project, I print out the same rotation values the same way its done in the example but the results look like this and produce an incorrect rotation:
As you can see, it looks like something is slightly off with the math. I first tried to simply switch the pitch and the roll but that didn't really help too much. I think the answer might be in using UKismetMathLibrary::ComposeRotators() to combine the rotation by 90 somewhere or rotate the rotator?
Edit: Here is the code used to calculate the rotation for the gun when the second hand grabs it (second hand is not attached but the first one is attached).
Ok, I figured out the issue and it will take a little bit of explaining.
The two handed gun I am rotating is a series of static meshes that are parented together like so:
When I originally posted this, I was grabbing the handle with the primary hand which attached and worked correctly. But when I grabbed with the secondary hand to rotate the gun, it rotated the wrong way (my original problem with it off by 90 somewhere). This is because you are not supposed to rotate around the handle but actually rotate around the GunRoot.
The correct way to do this is to attach your hand to the handle but then Rotate the GunRoot Component and not the handle. If you try to do this out of the box the gun wont rotate and this is because the GunRoot is a USceneComponent and needs to be attached to something grabbable and moveable (UPrimitiveComponent). Below is how the GunRoot is attached to the handle. Once I had this in place, I was able to pick up the gun and rotate it correctly.
The above code was the key to get it working because it attaches the GunRoot to the handle. I thought this was already done automatically because of the hierarchy in the first picture but apparently not, the results don't lie.
Check the skeletal mesh of the character in both projects and make sure the right hand sockets have the same rotation.
answered Feb 28 '18 at 09:52 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here