Download

How to convert World space location to a Skeletal mesh component space.

I have a location in the world space… A point.

I want to know its location in the component space of the skeltal mesh component.

I tried a lot of things but still can’t a method that gives the correct results.

The method I use for this is to use the inverse of the component to world matrix. The code will look something like this:



FMatrix LocalToWorldInverse = SkelatalMeshComponent->ComponentToWorld.ToMatrixWithScale().Inverse();
FVector LocalPosition = LocalToWorldInverse.TransformVector(WorldPositionVector);


Didn’t seem to work in my case.

Basically what I am trying to do is, I got weapon that is attached to the players right hand. The weapon has a socket. I want to move the players left hand to the socket location of the weapon using 2 bone IK.

The weapon socket location is in world position. I want to shift it to component location so I can use the 2 bone IK on it.

The nearest effect I could get was this…


		FVector WeaponWorldLocation = GetCurrentWeapon()->Mesh3P->GetSocketLocation("LeftHandAttachmentLocation");
		FVector WorldRootLocation = GetMesh()->GetBoneLocation("Root", EBoneSpaces::WorldSpace);
		FVector LocalRootLocation = GetMesh()->GetBoneLocation("Root", EBoneSpaces::ComponentSpace);
		FVector RootWeaponDiffecent = WorldRootLocation - WeaponWorldLocation;
		FVector WeaponLocalLocation = LocalRootLocation - RootWeaponDiffecent;

		return  WeaponLocalLocation;

The transform that worked for me is…



FMatrix LocalToWorldInverse = SkelatalMeshComponent->ComponentToWorld.ToMatrixWithScale().Inverse();
FVector LocalPosition = LocalToWorldInverse.Transform**Position**(WorldPositionVector);