Can you make a Plane FACE the camera via it's Material only?

Has anyone had success in making a plane always FACE the camera via it’s material?

There are a few proposed solutions online and a Sprite node that are very useful, but do NOT do what I want.

The Sprite node (any many solutions online that I tried) ORIENTATE the rotation of the object to match the camera, making it “parallel” to the camera at all times:

That’s NOT, what I want.

I want to rotate the object to actually FACE, the camera.

Image Reference:
make_plane_face_camera_via_material

Why am I trying to do this?

I am trying to place a card (Plane) in a scene that aways faces the camera.

Most code online (and the Sprite node) rotate the object to the “opposite facing” of the camera, making it parallel, which is not what I want to do. It causes this problem as the Plane gets towards the edge of the screen:


(It intersects with the sphere because it’s trying to remain parallel.)

To solve this, the plane needs to always be FACING the camera. Like this:


(I have only been succesful getting this to work on one axis, can’t figure out how to do both.)

I know this can be done in blueprints, but I’m trying to learn to do it in the material.

Is it possible?

Any help or links would be appreciated! :smiley:

Thanks for your response, I have seen this video.

The issue is, it only works on one axis.

If you move above the object, it will not face you.

I need it to work like this, but on both axis so it’s always facing the camera from every angle.

Has anyone done this before?

I was able to calculate the vertical rotation.

I tried combining them both but seeing as the world offset is based on vectors instead of quaternions I seem to be getting some flipping of the coordinates at times. Perhaps a more math savy person could help make it more stable.

High res

pure code
material.txt (162.6 KB)

I’m guessing the inconsistency may come from the input orientation. One probably needs the information fed from the previous transform.

Thanks, thats the exact same math nightmare I ran into when trying to solve this lol. :dizzy_face:

I did find a solution, it was “hidden” in the Content Examples project (of course :sweat_smile:):

It’s deep within the Math_Hall level (3rd to last demo 2.20), name of the material is “M_Camera_Vector_to_Object”.

M_CameraVector_to_Object_Material

Here’s the material for it, hooks right up to WPO:

Note: I don’t know what the unconnected 1,1,0 vector multiplied by ThirdOrthogonal Vector3 does or where it goes, but I left it in for completeness.

Info:

  • To see it update in editor, I had to change the Actor Position node to a Object Position node.
    fc_swap_actor_pos_to_obj_pos

  • Width and Height control the scale of the object that the material is applied to.

  • To make it scale from the center, subtract 0.5 from TexCoord of Y axis.
    fc_subtract_5_from_texcoord

  • To control scale with Transform > Scale in the editor, multiply width by ObjectScale > X, multiply height by ObjectScale > Y (or Z).

2 Likes