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.
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.
answered Jan 02 '15 at 09:34 PM
Asher S Einhorn
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
answered Jan 02 '15 at 12:27 PM
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 ;)
answered Jan 03 '15 at 12:05 PM
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 ;)
answered Jan 03 '15 at 12:15 PM
answered Jan 03 '15 at 06:28 PM
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 :)
answered Jan 04 '15 at 03:54 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here