Is there a way to get relative location of one actor relative to another actor?

So for example, actor red is at 1,1 in world location and actor green is in 3,3 in world location.

Is there a method to get the location of actor red relative to actor green, just like in this graph, where actor red’s relative location is -2,-2 wrt actor green.

Help pls?

image

vector - vector

I feel you’ve answered your own question.

Thanks! I came up with the formula ( Green Actor Location - Red Actor Location ) * -1 = Red Actor Relative Location wrt Green Actor

Never thought it would be as simple as a single node lol

EDIT: So I did some testing and I would still need to multiply the value by -1 in order to get the accurate relative location.

1 Like

@Everynone Would you happen to know how I would go about setting the relative location too?

The order of operation matters.

image

This will give you -2/-2

Would you happen to know how I would go about setting the relative location too?

This is a bit ambiguous. Could you elaborate?

If you have have a relative vector and want to apply it, you’d add it to another non-relative vector.

Hey @Zarrar2802

can you tell us how your actors are managed? Are these different actors/meshes in ONE blueprint or are these also different blueprints.

Case 1 : You can use SetRelativeLocation. These will set the relative location of one component relative to its parent
Case 2: You will have to get the location of your e.g. GreenActor. Then GetLocation of this actor, add your desired RelativeLocation and plug this in as the destination of SetWorldLocation for e.g. your RedActor

And for your relative location: When you use VectorA-VectorB A will be the one which you want to move relative to B.

Could you explain a bit further please. Basically, I want to be able to SET a new relative location wrt. to the other actor. So if X world location of actor 1 is 10, and X world location of actor 2 is 20, then X relative location of actor 1 wrt. actor 2 would be -10, since actor 2 is set as origin.

So if I wanted to set the X relative location of actor 1 wrt. actor 2 as +10, aka in the world, it would become X = 30

How would I go about doing that? I hope I was able to explain my issue.

Yes these are all separate actors.

Yes I think this will work!

Get the actor from the class you want with getworld into your main actor class and then set relative location to main actor to the component you got from the other class with get world.

They are all subclassing so you can do that.

That way you can attach as many actor components from other classes into the class that you want to be the root component of all the components from other classes.

It’s doable with C++

Both answers from @Everynone and @L1z4rD89 helped solve my issue. Thank you everyone! <3

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.