I am no familiar with how transformations can be made in UE4, I’ve seen many functions but don’t know how to use them.
For example if I have a Socket location and rotation (which are in local space I suppose), how can I get the world location and rotation?
FTransform has GetRelativeTransform and GetRelativeTransformReverse.
The former can be used to go from local to world space, the latter the other way around.
Coincidentally, you can get a socket’s world space location anyway; it contains a relative location and relative rotation var, and also has GetSocketTransform and GetSocketLocalTransform.
With ‘relative’ do you mean world coordinates?
Sorry I have just a little of knowledge related to OpenGL where I am used to having transformations from model space to world space and then to clip space using matrices.
So if I have the position ‘FVector Pos’ of anything in character space for example and I want to know where it is in the map what I can use?
The only thing I have found is:
FTransform Transf = GetTransform().GetRelativeTransform(Pos);
and then get the position and rotation with:
FVector Location = Transf .GetLocation();
FRotator Rotation = Transf .GetRotation();
Let me edit that post - I meant local space and world space (relative coordinates are the same thing as local coordinates).
You talked about transformation matrices, which is what an FTransform can be thought of as being. It has members that will let you get the location and rotation (GetLocation() and Rotator() ).
Like mentioned before though, it’s not common you’ll need to do this, many objects will have functions to do these kinds of things already.
I am trying very hard but I am still unable to get the correct behaviour.
I want to spawn something in the socket location and I am trying this now:
FVector AAORGameWeapon::GetMuzzleLocation() const
{
USkeletalMeshComponent* UseMesh = GetWeaponMesh();
return UseMesh->GetSocketLocation(MuzzleAttachPoint);
}
FVector AAORGameWeapon::GetMuzzleDirection() const
{
USkeletalMeshComponent* UseMesh = GetWeaponMesh();
return UseMesh->GetSocketRotation(MuzzleAttachPoint).Vector();
}
// CURRENT CODE I AM TESTING
FVector MuzzleLocation = GetMuzzleLocation();
FVector MuzzleDirection = GetMuzzleDirection();
MuzzleLocation = GetTransform().TransformPosition(MuzzleLocation);
MuzzleDirection = GetTransform().TransformVector(MuzzleDirection);
The actor I am spawning is created very far from where it is supposed to be.
Is it still a problem with transformations in this case?
GetSocketLocation and GetSocketRotation both operate in world space and should give you what you need.
The issue you’re having is probably being caused by something you’re doing elsewhere.