Download

Seamlessly switch socket attachment during animation?

I’m adding a new first person weapon, and I want to be able to switch the attached weapon from the left hand to the right mid-animation.

I need to calculate what the meshes new rotation and translation will be, based on where the two hands are when I make the switch (so the transition is smooth).

However I just can’t seem to calculate the rotation correctly when doing the switch to the other socket.



simulated function SwitchFirearmToRightHand()
{
    local vector leftHandLoc, rightHandLoc, newWeaponMeshTranslation;
    local rotator leftHandRot, rightHandRot, handRotDiff;

    UDKSkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation('Left_hand_socket', leftHandLoc, leftHandRot);
    UDKSkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation('Right_hand_socket', rightHandLoc, rightHandRot);

    newWeaponMeshTranslation = leftHandLoc - rightHandLoc;
    handRotDiff = leftHandRot - rightHandRot;

    Firearm.SetBase(self,, SkeletalMeshComponent(Mesh), 'Right_hand_socket');

    Firearm.Mesh.SetTranslation(newWeaponMeshTranslation);
    Firearm.Mesh.SetRotation(handRotDiff);
}


Make sure the .Y value is a positive value.

If i remember right. The left hand .Y is a negative number. while the right hand .Y is the opposite > positive number.