x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I work out one object's relative position to another?

I'm pretty sure you can do something like... multiply one object's coordinate space by the other, and then see what it's position is... but I can't quite remember or seem to work out what to google let alone the best blueprint nodes to use!!

How would I work out a characters relative position to a cube in the level for example?

To elaborate, in the following picture (sorry about the quality....) I want to find the players (P's) RELATIVE y offset. RELATIVE to the cube's own coordinate system and rotation. I can't do it in world space because no matter what orientation I place the box I want to get left and right across it as a y value.

alt text

Product Version: Not Selected
Tags:
capture.png (12.3 kB)
more ▼

asked Jan 02 '15 at 11:37 AM in Blueprint Scripting

avatar image

Asher S Einhorn
650 93 79 180

avatar image Wallhalla Jan 13 '15 at 08:23 AM

Hey, i see this question is still open. Is your problem solved? Did my answers help you out? Or do you still have some problems with this?

best regards

(comments are locked)
10|2000 characters needed characters left

6 answers: sort voted first

I found this solution to my problem. In this graph I'm getting the location of the actor (1.) relative to the position of 2. I would still like a more flexible solution involving two transforms.

alt text

capture.png (102.7 kB)
more ▼

answered Jan 02 '15 at 09:34 PM

avatar image

Asher S Einhorn
650 93 79 180

(comments are locked)
10|2000 characters needed characters left

Hey there im not quite sure if i get you right but could it be that you are looking for Get Actor Location, which gets you the LocationVector of your desired object?

If you mean with relative Position between Character and cube the vector between them you could substract bot actor location and its returning the vector. F.e. From Cube(Point A) to Character(Point B) you could substract B-A and you get the direction vector (DirV). The relative positionnow would be: PointA + DirV = PointB

Was that you intention?

kind regards Wallhalla

more ▼

answered Jan 02 '15 at 12:27 PM

avatar image

Wallhalla
181 5 10 20

avatar image Asher S Einhorn Jan 02 '15 at 08:06 PM

I want to translate one object into the coordinate space of the other.

(comments are locked)
10|2000 characters needed characters left

In computergraphics there is a thing called modelviewmatrix (f.e. in OpenGL) and if you draw an object you transform from the current matrix with a x,y,z transformation. Then you can overlay the current "world"matrix with a new one, which has the latest transformation/rotationmatrix as root.

F.e. you first place a cube somewhere in world space, there is the first transformation worldcoordroot + cube location = new location in world root. Overlay this and everything drawn next will be relative to new location + new drawn object = next new location.

When i got you right, you want to set f.e. the players location with x,y,z added from the cubes matrix transformation right?

To do this i would get the baseobjects transform as base. From this point you can do any kind of math operation and the result seems to have the relation you wish.

The trick is: Draw the first object (or spawn or whatever), this is your base and set the next object which shall behave relative to your base to the exact same position as the base and then add the additonal transformation. However this is how it works for me when i did play around with computergraphics :)

maybe this helps or maybe i still got you wrong ;)

more ▼

answered Jan 03 '15 at 12:05 PM

avatar image

Wallhalla
181 5 10 20

avatar image Asher S Einhorn Jan 03 '15 at 12:13 PM

It's not a problem specific to computer graphics, it's a matrix multiplication issue. Anytime you describe something's transform with a matrix, you can do this. it's very simple, I think you just multiply one by the other or something. I just can't remember how.

(comments are locked)
10|2000 characters needed characters left

oh sorry i mixed the overlay behaviour.

Actually if you spawn something into the world this will alter the modelview, so if you spawn the next it takes the altered modelviewmatrix as base.

I assume to work correctly inside the editor, each time an object is put into the world there is an overlay of the worldmatrix (PushMatrix) and after that there is a (PopMatrix) this results that every drawn object is relative to the worldcoordinate space.

To be honest i really would like to know how epic does this magic for real, because i dont know if im right with this.

However i dont think set up a new coord space is not the right thing to do here ;)

best regards

more ▼

answered Jan 03 '15 at 12:15 PM

avatar image

Wallhalla
181 5 10 20

avatar image MrRabbit Feb 25 '15 at 08:48 PM
  • for all your effort!

(comments are locked)
10|2000 characters needed characters left

like that? alt text

example.png (26.9 kB)
more ▼

answered Jan 03 '15 at 06:28 PM

avatar image

Wallhalla
181 5 10 20

avatar image Asher S Einhorn Jan 04 '15 at 01:23 PM

Yes I think so! but what's the algebraic shorthand? and how would I achieve this in blueprints? Thanks so much for your help.

(comments are locked)
10|2000 characters needed characters left

ill try it with that, and sorry i cant test that right now

"To elaborate, in the following picture (sorry about the quality....) I want to find the players (P's) RELATIVE y offset. RELATIVE to the cube's own coordinate system and rotation. I can't do it in world space because no matter what orientation I place the box I want to get left and right across it as a y value. "

Inside the Player you get a reference to your cube, i think like you did in the picture before.

Call GetActorLocation from Cube (Vector 1) Call GetActorLocation of your PlayerActor (Vector 2)

Then substract them. Vector2 - Vector 1 -> and you will get a Vector which has the direction Cube to Player That means break down to the y value of that vector you would have the amount of y units you need to go to get to the player´s y-origin position (the mentioned offset)

Otherwise substracting Vector 1 - Vector2 and break down the result to y component you will get the y value of how many y units you need to go to be at cube´s y-origin position

maybe that helps :)

more ▼

answered Jan 04 '15 at 03:54 PM

avatar image

Wallhalla
181 5 10 20

avatar image ScottSpadea Jan 20 '15 at 01:04 AM

that still sounds like you are in world space with that solution, not in the local coordinate space of the box, like the question wanted.

you used 2 positions as inputs, without using the rotation of the box at all. so you didn't use enough information to transform into the box's local coordinate space. before you can subtract those vectors, you need to rotate the players position around the box, with an equal and opposite, "inverse rotation" of the box.

im sure there is a way to do it from scratch, using nothing more than a mess of "sin(yaw) * cos(roll) " nodes, but without blueprints supporting matrices, you might want to do this in c++.

another way to state the problem from the box's view, is: you want to rotate the players position around the box, with an opposite rotation than the box, then subtract the vectors to find the distance and take its Y component as your answer.

to do that rotation, usually you multiply by the inverse of a rotation matrix for each axis of rotation, in the same order the engine uses to rotate the cube. if you don't use the same order, gimbal lock can throw the cube's rotation and the resulting data out of sync.

a hacky solution might be to have an invisible actor that you move to your player and parent to your cube, then you find its relative location to its parent, and take the Y component as your answer. to constantly update this, you would have to (unparent, move, parent, test) for every update, but if you only need this info rarely, than this hack might work.

imagine trying to do this kind of math in blueprint, with nothing but basic trigonometry nodes: https://www.youtube.com/watch?v=HQYsFshbkYw

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question