How to: Actor looking to you, when you are not watching

Hi guys,

I asked this question before and I’ve got a solution, but this was pretty rough and to the time being, I had no clue about blueprint scripting, so this answer was okay for me.

Now, after a lot of iterations in terms of level design, I realized, this solution isn’t stable at all. Sometimes it works, but most of the time it won’t. This is because of the node is used - ‘was recently rendered’.
This node isn’t meant to be used like this - it is more for debugging.

So I came up with the same question like before now - what would be a good solution to get the desired effect?

First of all my current script:

I have a ‘character’ ingame, who is more like a statue. You know doctor who? The weeping angels?
They are turning and hunt you, whenever you don’t see them. In a blink of an eye, they were closer. You turn your head - they are coming closer.

For my purpose, I only need the rotation part, but I don’t know how to get this work.
Maybe via path tracing? Whenever it hits the statue, nothing happens and after turning your head, the statue moves?

I already tried it, but I couldn’t find a solution to get it to work with the full field of view.
I hope you can help me - thanks!

Best regards,

Those things make my skin crawl.
I can think of a way to do this but It’d be terribly inefficient and I’m sure there would be better way.

You could potentially do line traces at FOV ± 5~% and 10% and use them as toggles for each other and to toggle the statues movement. But honestly It would just be a mess.

Another way could be a just wedge shaped collision and just disable movement on them via beginoverlap (have it invisible/nocollision cept overlap for statues ofc).
But again not exactly very efficient.

Third option I can think of would be to get players rotation in relation to angels location and disable angels if they’re in the direction player is facing. This is probably the best way of the ones I can think of but I’m not that familiar to with exactly how it could be done.

Have you tried using the DOT product node to determine if an enemy/object is in the player’s line of sight and if not have the actor rotate to face the player/do whatever you want to do?

That’s a good idea, but does it detect whether any part of the player’s pawn is in the AI Pawn’s camera frustum?

The DOT product doesn’t care about the AI camera. It just tells you the angle between 2 actors. It is used for field of vision calculation. So you determine what the player is able to “see” based on how large a value you accept for a DOT product.

Ah, that could work. It wouldn’t be exact, but if it doesn’t need to be exact, then it would be pretty performant and easy to set up. Just takes a lot of tweaking to get it to match up with the player’s camera FOV (which would match the player’s experience of “I see you!”) unless someone here knows how to convert between FOV angles and DOT product.

You could try using the set focus and clear focus nodes along with the line of sight to nodes. The line of sight node will return a boolean result telling you if the enemy is within your line of sight. If the result from the line of sight node is false, then you can use a branch to execute set focus. If it is true, you could use the clear focus node.

No, it doesn’t need to be perfect. It’s more like a gimmick than a real gameplay mechanic.
The statues are fixed on the positions and more of use in decoration purposes.

But please more slowly … this is hard to get for a newbie like me.
I understand the general idea behind this, but I am no programmer. Could you explain it more in depth or even visualize it?

I am a ‘intermediate beginner’ and more of an artist - these scripting things are hard to understand for me. I try to get better in it, so I can solve problems on my own and be a help for others here… but at the moment I have no clue. Sorry :confused:

Is your suggestion similar to the solution by BrownWolf ?

Thanks for your help - I tried it, but I don’t got a clue how to do it.
I saw a tutorial by Mathew Wadstein and he used this ‘Line Of Sight To’ node, but I can’t adopt it to my script and your suggestion. Is your answer or thought similar to the one of and Nebula Games Inc ?

The dot product of two vectors gives a percentage (between 0.0 and 1.0) of how much they are facing the same direction. so 1.0 is same direction. 0.0 is perpendicular, and -1.0 mean facing opposite directions.

Can you show a screenshot of how you tried to use this or the lineofsight node?

Why don’t you post some screenshots of what you are trying to do? There’s probably a small mistake in there somewhere that you are not seeing. For example, your logic might be correct, but there might be some setting that you have to enable on the enemy. Either post your pictures here, or in response to .

Sorry for the late reply.

I am totally lost in this blueprint script thing, because there is no real documentation about the line of sight to node and I can’t even find the ‘set focus’ and ‘clear focus’ node BrownWolf mentioned.

Anyway - this is the only ressource I have found:

The setup is super simple. Feed the line of sight to node with an execution pin and set a new value - in this case a text value. Well, I thought I could do it the same way… but with no success. I swapped the ‘was recently rendered’ with the ‘line of sight to’, but nothing happend. The rotation works, when the branch outputs a false value… but they are rotation all the time. Obviously.

And here I stuck - well. Not at all.
I think I created the node setup you mentioned with the dotproduct: [BlueprintUE][2] … but I don’t know how to use it.

Sorry for the late reply - I added an answer in the comment section of my post.

What you could do is something similar to the following:

Get the Cameras forward vector and a vector that points from your camera to the actor you want to move (camera.GetWorldLocation - MovingActor.GetWorldLocation) and calculate the angle between those two vectors by using the dot product and ACOSd ( How to get an angle between 2 Vectors? - Blueprint - Unreal Engine Forums ). Check if the angle is bigger than half of your field of view. If so, the Actor is outside your field of view and the player can´t see it.

Hope that helps.

The BP below should give you a hint on how to use the dot product in that case. Just put this into your statue’s BP. It still has some flaws (i.e. when the statue is very close to your character) but I hope it shows an idea.

You only seem to be using the false output. Right now in your solution, nothing happens when there is a line of sight, so maybe that’s why the enemy is always rotating.

You mentioned that you can’t find the focus nodes. Right click somewhere on the grid to bring up the node menu. Uncheck the context sensitive box, then place a set focus node and clear focus node onto the grid. From the branch, connect the false output to the set focus node so that when the player is not looking, the enemy will lock onto the player. Connect the true output to the clear focus node so the enemy will not lock onto the player when the player is looking at him. Don’t forget to recheck the context sensitive box.

Okay, we get closer.
This is what I got - AI Controller posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

I think it’s pretty much that you told me to do, right?
The problem is, it works like before - they are always rotating, but this is a good sign I think, because in the core it works - somehow.

The problem is the Target Input of the set focus and clear focus node, because it just eats a AI Controller. Never used AI Stuff before, so I googled and I created an AIController with a basic behavior tree. I don’t know this is even necessary, but it’s there.
Now I need to get the AI Controller into the Statue Blueprint. Actually this Blueprint is a pawn, so I thought a pawn could not handle it and so I created a character blueprint. Well, here I have the same problem.

I copied all of the logic in the AI Controller Blueprint and added the statue … well, no chance aswell. Sorry, when the solution is pretty obvious, but this is a unknown territory for me :confused: