Getting the vertical angle between an object and the camera

I’ve gotten a bit stuck trying to write a blueprint that swaps out a material based on the vertical angle between the player camera and an object.
Note : the direction the player camera is looking does not matter. All I care about is the vertical angle between the two.

cameraAngle

I tried doing this just in the material blueprint and sorta kinda got it to work but it became very dependent on where the camera was pointing, and the result was not exactly what I was looking for, in that the materials changed across the polygon dependent on where the camera was (instead of a clean ‘flip’ from one color / material to another), but also it was taking into account the camera heading as well as pitch (because I did it with vectors and a dot product):


result

I want the entire object to instantaneously flip from one material to the next. It doesn’t really matter to me if I do it in the material, or the object blueprint, but some general guidance would be appreciated.

I think you should do the math in your object’s blueprint.

Here’s your diagram with some added math that should help.

CameraVerticalAngle

So, a is the distance between the objects in XY space, and b is simply the absolute difference between the Z components of the locations. To get the “Vertical Angle”, just divide b by a and feed that into the “atan (degrees)” node.

Hope this helps!


Also, thanks for the detailed diagram and clear question. It makes it much easier to answer!

3 Likes

OMG that’s so frickin’ obvious - I looked right past it.
And the math is quick too. I’ll use that as my starting point - thanks !

And you’re welcome on the diagram and question :slight_smile: