Need help with finding rotation of line trace.

I am working on a game that includes a feature that allows the player to place sticky notes on static meshes. My original method for finding the correct rotation was doing 6 line traces (1 for each direction) then rotating the sticky note accordingly.

This works fine but I want to know if it’s possible in visual scripting to find the rotation of a face in a static mesh based on where the line trace hit.

Sticky note example:

Below is an example of where I want to place the sticky note and have it face to the left (so it’s readable).

Not sure if I am overthinking it but I cannot find a solution. Any help is appreciated :slight_smile:

You can break the hit result and use the Normal pin to get the direction (not rotation) that your item should face. To set your item’s rotation to face that direction, you can calculate what rotation that unit vector represents and use the result.

This calculation can be done with multiple ways. One way would be using the dot product & acos method (though there’s an additional step there to include negative results) and another way would be using the Find Look at Rotation node. In both ways, we’ll compare the angle between our unit vector with the +x direction (x = 1, y = 0, z = 0) which is considered 0 degrees around z axis in world space.

Hope this helps! :innocent:

1 Like

This helps me get the rotation but the note still won’t look up or down properly.

I am not familiar with the Dot Product method so I tried the ‘Find Look At Rotation’ which makes sense but I may be doing the math wrong here.

My script:

The 4 walls work fine

The issue is when I want the Sticky Note to face up or down.

Aight, I’ll provide you a blueprint code showcasing how to calculate the rotation a unit vector is facing in a minute. Lemme just launch my PC tho.

And here it is :blush:

@TTGR.Pro, in your case, the vector is already a unit vector btw

1 Like

This works but I still need the Sticky Note to be able to face up and down. This rotates it around the Z axis which is just 1 part of my solution. Can I have help solving the issue of it facing up and down ?

Thanks!

Hey @TTGR.Pro, I won’t be able to use my PC for like an hour. I’ll edit this post of mine when I get to launch my PC again. See you then!

1 Like

Thanks for getting back to me so quickly. I have a solution but not sure how consistent it is. I use the Normal then just multiply the Z by -90.

For my specific situation this is working fine and I mark this as solved. Thanks for your help :slight_smile:

1 Like