2
$\begingroup$

I'm pretty new to blender so probably i'm going to say wrong terms or function in this question, feel free to ask for a better explanation if necessary.

I have created a material tab that makes the images in the planes show only when the camera is looking at them at a certain angle (like the NPC in the Doom 1993 game). In this case I set the angle to be 90° degrees so that when the camera turn past that point, the plane in the front became invisible and the one on the side shows up (In this example I used only 2 planes for simplicity, normally there would be 8 planes each one turned by 45° in an octagon like shape). I use some math with vector and arcosine to do the trick as shown in the example. There are two colored planes on the side to show better what's happening: when the plane is red it means is showing the guy, when is green it don't. example 1

This is the node used for each plane: enter image description here

The rotation works fine, the true problem is that the plane is still acting like... well, like a plane. I wanted to make the guy rotate and follow the camera at the same time (Billboard if I'm correct). My first thought was to use a simple locked or damped track set on the camera, but unfortunately this is the result: with locked track The plane shows both the guy because they are always facing the camera and so of course the camera is always in the 90° cone.

So here's my idea: I make two sets of planes, the first one (Planes 1) will be invisible and immobile, while the second set (Planes 2) will have the image to show, the material and the locked track. My idea was to make Planes 2 show not using his vector (that if I'm correct its use in the material tab) but the vector of Planes 1, so that the camera take in consideration the angle or vector of Planes 1 while Planes 2 will be free to rotate. example 1 example 2

Is it possible to make a link like this without using any script? If it isn't possible, can you recommend another solution without any script to make a character rotate and act like a Doom 1993 game NPC?

Again, I'm sorry for any error while typing or incorrect terms since I'm new to blender and this is my first question, I tried to be as clear as possible but, if necessary I'm ready to give you any information that you need to resolve my problem.

$\endgroup$
2

2 Answers 2

2
$\begingroup$

You're on the right track. Well, tracks. You need to both billboard this guy (kinda billboard him, we'll get to that) and check the angle.

So first, let's see why we need to billboard him:

enter image description here

Let's say your little dude is running at a diagonal to the camera. We're still seeing his side, but the camera isn't pointed directly at the plane. Just like the monkey on the left, he's going to get distorted by the angle to the plane. So we always need the plane to be pointing at the camera. We can do that with a locked track constraint. Because your planes have had rotation applied (+Z is up, +X is right, and plane normal in object space is -Y) we'll do a locked track, lock Z, track -Y to camera. Now we can see that issue is fixed:

enter image description here

Why locked track instead of damped track or track to? Because although we want our little dude pivoting on the up/down axis to track the camera, we actually do want him foreshortening if the camera is ever raised above him. That's why we're only kinda billboarding him: there is an axis where we won't.

Now, we still need a way to indicate facing, so that we can mix between front and side views. But because we're tracking the camera, we can no longer use our object coordinates to measure facing. -Y is always facing the camera. We need something new to indicate facing. We'll do that by creating an empty at the location of the plane, then parenting the plane to that empty. Our empty will carry the information about facing, even as our plane rotates to face the camera.

Since we're using an empty to measure facing, we now need to compare a vector of the empty to the +Z vector of the camera. That's not so easy to do in pure nodes (it's possible, just confusing and painful.) Let's slog through it with drivers instead, doing everything in a way that's totally clear.

We want to know the world space vector associated with one of our empty's axes. To find that out, let's make another empty, move it in one axis, parent it to the other empty, and then subtract the locations. We can use drivers to acquire those positions into value or combine XYZ nodes:

enter image description here

Now, we'll set up the nodes to compare that (world space) vector to where our camera is pointing:

enter image description here

We convert the camera's +Z vector into a world space vector, then we drop the world space Z component (we don't want it switching views when we adopt a bird's eye view!) We normalize the vector and compare it to the vector we created with our drivers. If the absolute value is greater than 2^0.5/2 (cosine of 45 degrees), then we're facing front or back; otherwise, we're facing to the side. We can use our knowledge of this facing to mix between two different texture lookups. (Ideally here, we'd actually be mixing between four, or more, different lookups, but I'll leave that problem for another day. This is already a pretty long answer.)

Images are not packed into that file, in order to spare their server some bandwidth.

$\endgroup$
2
  • $\begingroup$ This kinda work even if for some reason the plane doesn't get affected by shadow, do I have to put a principled Bsdf on the color input on mix color? Also, could you please continue the explanation on how to expand with 8 images? I even made a question apart with more details: blender.stackexchange.com/questions/244601/… $\endgroup$
    – Er Coso
    Dec 1, 2021 at 17:09
  • 1
    $\begingroup$ @ErCoso I'm doing emission, so there's no shadow. If you want shadow, you can use a diffuse or a principled (or even a glossy). But you probably don't want shadow: the actual geometry that will be shadowed here is just a plane, after all. I'll check out your other question. $\endgroup$
    – Nathan
    Dec 1, 2021 at 18:05
0
$\begingroup$

If i understand you right, you need the track to constraint.

So select your human/plane, add object constraint...

enter image description here

choose track to and choose your cam as target.

enter image description here

you can - if your camera should also look always to your plane add an object constraint to the cam as well with target "plane".

result:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.