Lerp between surface normal and camera?

Hi everyone,

I’m trying to create a setup when hovering over an object that I get a semi-3d feeling pointer object as the cursor.

At the moment I’m doing this via a linetrace which gives me the surface normals and hit location. I’m then mixing this with a ‘Lerp Rotator’ node from my camera object so that the cursor stays kinda half oriented to my camera.

This is working pretty well for most objects, but the problem arises with more sharp objects like the cube where it seems like the normal or rotation for the cursor twists back around in only 1 direction (See below video for demo)

I’m wondering what the best approach would be so that even for these sharper objects it acts more like the sphere?

Any help would be greatly appreciated, thank you!

Desired outcome (in red):

Current setup:

The desired outcome as presented might be quite difficult to achieve, because the top part of the Cube is always the same normal, regardless of whether player looks at it from the left side or the right side… To be perfectly consistent you’d have to track the previous orientation of the widget and somehow take that into account in the calculation

However you could use a simpler approach, which consists in biasing the widget orientation using Camera’s Z vector. It will give slightly different result but is much simpler and should be more consistent overall.

1 Like

A spline based on last X number of mouse location / normals samples could work?

1 Like

Thanks for both your responses - @chatouille I tried following your setup but unfortunately it seems to only make a very slight rotation to the cursor in my case.. would you mind showing the results that gave you?

@Shmoopy1701 Yes exactly, would I be able to construct that spline based on the position of my character/camera so that it the normal would adjust in that direction?

I realised part of the issue is that the normal is always constructed perpendicular to the hit normal, so by slightly offsetting the hit location, I was able to orient the cursor to my liking.. now I’m just trying to figure out how to adjust this offset so it’s driven from the vector between my hit location and the location of my character/camera?

1 Like

That would be controlled by the Lerp Alpha - I used 0.25 because my first parameter was the HitNormal, if you set it up the other way around then 0.25 would result in very slight rotation, try 0.75 instead.

Here’s how it looks for me

1 Like

Wow that looks perfect!

I’ve tried to adjust my setup so it matches your blueprint but I’m sadly not getting the same results… I’m thinking maybe it has something to do with the transform settings as I see your using a ‘Set Actor Rotation’ node, whereas I’m using a ‘set world transform’ node?

You can see in the video the very slight rotation on the cursor, and then when I move around the object it doesn’t orient to my player :frowning:

Blueprint:

What is HEAD UIBOX TARGET ?

I think one of your vectors is reversed. You are doing “find look at rotation” from HitLocation towards that variable. In my case the camera vector goes from Camera towards HitLocation so most likely it’s the other way around. Try not multiplying the HitNormal by -1.

1 Like

Yes unfortunately already tried that, and it only flips around the cursor but the behaviour is exactly the same.

HEAD UIBOX TARGET is the object parented to my character’s head to create the vector between the HIT location and the head… or do I not need this and should replace it with the rotation directly from my camera?

I couldn’t see the node you shared before that was attached to your camera rotation, would you mind sharing what that is?

Yes this is how I get camera location and rotation

1 Like

ahh ok interesting I’ve never heard of that ‘Get Actor Eyes viewpoint’ node seems like a handy one.

Unfortunately still no luck tho.. it seems to just yield the same results - sorry to be a pain but would you mind sending a screenshot of your whole setup?

(I’ll try recreating the whole thing as you’ve got it and try and troubleshoot it that way)

Here’s whole setup

the CursorActor is basically a simple actor with a widget component, the component is rotated 180° to face -X axis. Actor is spawned by character on begin play (passing self as Owner).