Transfer Relative location to WorldSpace?

is it possible getting WordSpace From A Relative location??

describe your task in more detail

for example, I get relative location an object too first player we name it Fvector ObjectLocationToFirstPlayer;

then I set Y-axis 0 l.


now I want it back to WorldSpace.

there is any solution for this?

thx for replay.

If I understand you correctly, I think you need to do some simple vector math. The answer is World Location of Object = World Location of Player + Relative Location of Object

Starting simply:

1). Lets assume your player is at the origin in World Space. The location coordinates are (0,0,0)

  1. Assume an object is hovering over the player’s head at a relative location of (0,0,100)

  2. It is obvious at this point that the object’s world location is also (0,0,100) because the player is at (0,0,0)

  3. Now lets assume the player walks along the x-axis to (100,0,0) and the object’s relative location remains unchanged

  4. Now the object is hovering 100 units along the z-axis over the player’s position at a point in world space of (100,0,0)

  5. That location in world space is (100,0,100) which is the what you get when you add the player’s location plus the object’s location relative to the player: (100,0,0) + (0,0,100) = (100,0,100)

Thx For replay, but your solution only works if we are in perfect world axis :

FirstPlayer->GetActorForwardVector() == Fvector(1,0,0);
FirstPlayer->GetActorRightVector() == Fvector(0,1,0);
FirstPlayer->GetActorUpVector() == Fvector(0,0,1);

imagine your FirstPlayer move in 3D space first its moves 1000 unit to FRotatior(35, 48,-87) then its moves 500 unit to direction FRotatior(87, -54,67) now your axis vectors are something like this:

//hypothetical numbers
    FirstPlayer->GetActorForwardVector() == Fvector(0.5,0.86,0.3);
    FirstPlayer->GetActorRightVector() == Fvector(0.76,.15,0.4);
    FirstPlayer->GetActorUpVector() == Fvector(0.34,0.7,0.1);

now you cant (100,0,0) + (0,0,100) = (100,0,100) cause relative location remains the same ( cause its relative location to the first player and changing location and rotation of the first player doesn’t affect to it ) in this case, if you are using simple pluses, its pluses with wrong coordinates (x,y,z).

any help ?

You can get a world location provided you have the Parent transform (a transform in world space, like that of a RootComponent of an actor) and the Relative transform of the object in local space (relative to the Parent transform)

It is a two step process:

  1. Do a “Compose Transform” (that is what it is called in Blueprint) - note order of transforms matters

FTransform NewTransform = RelativeTransform * ParentTransform

  1. Get the location from the NewTransform

FVector NewLocation = NewTransform.GetLocation()

I should add: Check out CalcNewComponentToWorld function in SceneComponent.h which is designed to do Step 1 for you.

The best way to find these things is to know the types of classes the operation you are looking for applies to and then follow that trail in the API and engine source code.

In this case it also helps to “know the math” as it is easier to know I found what I was looking for.

So to do what you want involves FTransform (FTransform API Docs) where you can see it has the ‘*’ operator defined and the USceneComponents (USceneComponents Docs) where all the physically present in the scene components directly or indirectly derive from (Component Docs).

When I do this, I tend to look at the engine source code which made it easier to tell that the function seemed to do what you were looking for.

Thx its CalcNewComponentToWorld helped.

could I ask how you find it?

Thx for your time.