Need help with programming AI detection

Hello,

I making stealth game and I need some help with programming AI. For now my AI can only detect based on perception and distance, but I also want to add detection based on our character illumination. I found system based on blueprints that measures the level of illumination on skeletal sockets. The system calculates the overall lighting value from all of them.
Now the problem is that I don’t know how to use this value to make AI see me less in dark places. This is how my AI, and this illumination function looks like. I will show more code if needed.

Overall Illumination



AI


Hi there @Maoryss,

This topic has been moved from International to Programming & Scripting: AI.

When posting, please review the categories to ensure your topic is posted in the most relevant space. Hopefully, this category change will help you to get an answer.

In the meantime, good luck and happy developing! :slight_smile:

Hey @Maoryss!

So this all comes down to your personal design as far as the numbers go. But what I would do personally is simply GET your “Temporary Illumination Value” and bring it to the graph in the AI controller. Then from there, disconnect the “Successfully Sensed” from “Has Seen” because you’re going to use an AND node. So you can figure it out yourself, but I’d suggest something like:

Illumination Value * (Distance to target / Range Max)

And then check if that’s greater than a certain threshold (like .5 or something. You’ll need to tool around with it to see what feels good, this is where design tuning will need to happen). Then you’ll plug the Bool off that “>” check into your AND node with the “Successfully Sensed” bool and send that output to “Has seen”.

Basically:
If successfully sensed = true
AND
Illumination Value * (Distance to target / Range Max) >.5
THEN:
Sense target :slight_smile:

1 Like

Since they also have a detection speed variable that determines how fast they can be sensed, maybe multiply Illumination Value (assuming it’s 0 to 1) by that detection speed to get the new detection speed.

This would make it so that you can have a value that, if the light is lower than it, the player will never be sensed while also allowing for the player to be seen just a bit slower whenever it’s just a bit dark.

Absolutely! And you can do that after your “Get Float Value” and before your “SET DetectionSpeed”, just GET “Temporary Illumination Value” and multiply your float value by that before plugging into Detection speed. It should just then be a % of regular Detection Speed!

Thanks for the reply and for the ideas! I could not figure it out myself. I will try your way and check how it works.

Hi!

So I tried to implement your logic. Did I implemented “Illumination Value * (Distance to target / Range Max)” correctly? AI sees me, but does not detects.

Also do I have to somehow recall “Temporary Illumination Value” or just create new variable with the same name?
Sorry for my lack of knowlege but I programm something once a year : /

Hey @Maoryss!

Yes, you need to get your Temp Illumination Value and set it somewhere, because right now it’s passing in as “0” and I laid that out to use the variable you were already setting somewhere.

So you need to call on the blueprint that has Temp Illumination value, Get Temp Illumination Value, and plug that into “A” on your compressed graph there.

I would tell you where to get it but you need to give wider snips… Otherwise, we don’t know what code is where :slight_smile:

1 Like

So I found out that “Temp Illumination Value” is set to local and I won’t be able to get it out. But there is a function “Check overall illumination” that has “overall illumination” float.
I did something like this, but it still does not work. I don’t even know if it have sense.


Here is code that shows “overall illumination” during game:

Maybe I will link site where the code is described Christian Sparks — Unreal Engine Illumination Detection Blueprint...

Also forgot to mention I have also “evaluation of Detection” in widget blueprint

Hey again @Maoryss!

Let’s not go trying to reinvent the wheel! There’s no reason that variable has to stay private. Just make it public! It’s this little guy right here, the eyeball!

image

A value like that needs to be made public because it’s supposed to get passed around! :slight_smile:

1 Like

But there is no way to change that, or I don’t know it. I can only make new LocalVar. This is the parent class of a blueprint where this float is: BlueprintFunctionLibrary

obraz
obraz

OHHHHHHH Okay! This was a library function, I thought you wrote it! That’s different.

So you CAN just use the Overall Illumination instead of that Temp Val variable.

But there was an issue here in your code, for sure:

image
With this plugged in the way it was you were getting “A * (1)” always because B and C were the same value. You needed “value / range max”.

That should work appropriately now! If you need to see where things are messing up at this point, put print string nodes within the code to see where things are stopping! :slight_smile: You might need to play around with that detection value (the one that’s just in as 0.4) before you see a real difference.

1 Like

So I found the problem is with this “Check Overall Illumination” function. It does not give any value. Just shows Light = 0.0


But I will figure it out myself, because it’s just too much code to post here. If it works, then all that’s left to do is implement your ideas.

Thanks for your help and time!

The answer probably lies with your array of Light Probes! Really, that’s the only thing I can see there that could be the issue. Make sure those are set up and assigned correctly! That video above does cover that, yes?