# Get front of actor?

I am trying to determine front of actor even after it’s rotated.
So far my only solution was to: [Cursor Distance] to [Actor -50/+50 X and Y Offsets] and determine that way which side of actor the cursor is closest to.

I am wondering if there is an easier way? Like does actor know where front of it is?

Edit:

Tried “Get Forward Vector for Math and for Scene Component”, tried both: GetRelativeRotation and GetWorldRotation.

To debug it - added Draw Debug Line.
in every case - the debug line originated from 0,0,0 coords of the map.

Here is the result:

Edit:

This is my level blueprint (there will only be one level, so doesn’t matter I think)

not sure if im understanding you.

how about get actor forward vector. that will give you the direction the actor is facing, put another way the actors local +x in world space.

or if your trying to get the rotation from the actor to a given position then theres find look at rotation.

Yes I’ve tried that but in all cases - GetForwardVector returned 0,0,0 of the map.
See my edited question.

you should really explain the context a bit more so we can understand what your trying to accomplish.

are you trying to make the road piece face the direction of the cursor?

what you asked for was how to find the front of the actor or the direction its facing, the forward vector gives you the direction its facing in the form of a vector without magnitude it should be a -1 to 1 value. that may not be a perfect explanation.

anyways explain what your trying to do and then we will be better able to help you.

Sure, so I am trying to allow player to build road.
Each segment is 100x100 blueprint actor.
Action starts when player clicks on HUD button - then new blueprint instance is created and attached to mouse cursor and follows cursor in viewport.

When user clicks Left Mouse again - the newly created instance stops moving with cursor and is basically placed in word and added to global array of placed roads.

While the left mouse isn’t clicked - The instance is following mouse with constant SetWorldPosition.
Also - while new instance isn’t placed - I am running ForEachLoop which loops through global array of placed roads and getting distance to each (if distance is less than 50 - SNAP)

This is where I am stuck, I want new instance to snap to existing road element on sides of it.

So lets say I have piece of road at 0,0,0

I choose to place new road - new instance gets created, it follows mouse cursor - as I bring cursor to the back side of the existing road - it should snap next to it.

If I bring cursor to forward side of the existing road - it should snap to the forward side.

However - if I bring cursor to the left or right of the existing road - it should not as it is invalid action in my case.

I will put blueprint in the question.

alright i think i got the situation now and threw together a few examples. both examples use a basic road tile which consists of a plane and a arrow component as seen in the third picture. also the methods used here are a little different from yours since im relying on hit results under the cursor.

now for the second example i wanted to make the road tiles a bit more flexible so i could have things like T junctions and corners. for this i based the placement location not on the fore aft location but rather on the location of the arrows. this example is much the same as the last but instead of using the inverse transform and checks i made a function which gets the arrow closest to my cursor. ok so the function takes in a actor and a vector as parameters which will be the road piece in the world and the cursor location. we first get all the arrow components in the actor, then get the arrow at index 0 and set it as the closest (current closest local variable). we then run a loop for every arrow component that isnt index 0 and see if each one is closer to the cursor. if the arrow being tested is closer then we set the current as that arrow. the check itself is pretty simple we get the two locations then subtract them and get the vector length. once the loop completes we are left with the arrow closest to the cursor and we output that component. from there its just a matter of getting the arrows location and rotation and setting those values on our road tile that we are placing.

now these methods may not be the 100% best way to go about this but maybe it will at least give you somewhere new to work from.

Your first solution worked thank you.
I am just going through your BP and I am trying to understand the flow behind Inverse Transform Location pin and InRange.

In range only checks for Y value, if the road was rotated - would I not need to be checking for X in that case?

After playing around with many variables and options.
I think I might re-design my approach to this.

Instead I might go with getting existing piece of road from cursor that player hovers over and then snap to nearest edge based on that instead of looping through every piece of road in array and finding distance threshold, I realized that over the course of runtime - the array will grow and looping iteration will only get bigger so it’s probably bad approach.

Thanks for your answer, I learned quite a lot from it (I am still newbie learner into UE)

its checking the y in local space of the existing road piece. for example in my road tile the arrow is +X in local space, no matter what i set the world rotation to that arrow will always be +X in local. it a bit hard to explain. i guess a more apt analogy would be to think of a actor like a person, your +X will always be forward. no matter which way you face your nose will be forward to you. given that +y will be to your side and thats what we were looking to check in the example; is the cursor to the side of the road.