How can I check if player is being seen by AIPerception sight?

The idea is that the enemy will do different things, if i’m being seeing and a few seconds after I’m not being seen anymore.
However, the branch is always turning false. So technically, even though the enemy follows the player, it is returning it as not visible.


I get all of this on top.

Pleases help me. :slight_smile:

Hey @itsgoshi!

It seems you aren’t specifying which AI controller to use. If this is on your AI Controller Blueprint, you can get rid of this node and use the AI Perception component- you don’t have to use extra nodes for this, just “GetAIPerception”. :slight_smile: If it isn’t on your AI Controller Bluperint, you need to specify an actor in this node. All of the errors I can see are caused here, with this node.

image

image

image

Edit: @itsgoshi Updated with more description and images!

image
Hello! IS this what you meant?

So I did this. And while some of the red lines disappeared. I still get a not visible trigger the second the enemy sees me. This is what some of the other stuff looks like.


Try this: It’s basically the same thing with less confusing nodes.


On Target Perception Updated returns the stimulus and actor that was observed, if you need it.

Then IsSeen will be set for anything else you may need it for in your code. Then it answers true or false from there, going into chase or search locker events! :slight_smile:

I see you’re using “On target perception updated”. The thing is I was using that for an event where the enemy will be distracted by a thrown object. I’m assuming I can’t use it for both these events?

Also, I did what you suggested, and as soon as the ai loses sight of me, it just stands still. It is supposed to first go to the nearest locker. And if I’m not there, go to a random one.

You can, you just need multiple options. Only one event node. You can use multiple checks such as “== Class” to check if it is a thrown object class, or if it is “Character” class.

So Actor → Get class → == “Character”? → Branch, on True, run this, on false, run thrown object code. Things like that. :slight_smile:

:thinking:
IS this what you were thinking?

More like this!

You can’t compare actors to actors because they receive new names when they spawn, so they’ll never match! :slight_smile:

1 Like

That makes so much sense. The enemy kept chasing me even after I threw the object LMAO.

However, where do I put the is seeing bool now?
That would be the deciding factor in whether or not the enemy checks out the lockers or not.


This is where we’re at now

Tried to connect the object to the actor class, but the enemy still follows the player instead.

Okay, so there are definitely some things to fix up! :slight_smile:

It’s chasing the player non-stop because both of the == class nodes are BP_MC (I assume that is your main character blueprint). The one leading to “GoToNoise” needs to NOT be your player character.
image

Also, get rid of the cast in “GoToNoise”. That’s casting with no object and will create an error.
image

Finally, hook up the False/false output to be the “Check Lockers”.

So:

If sensed class == BP_MC, chase player. If not, move on.
If Sensed class == thrown object, investigate. If not, move on.
If Sensed class == Neither BP_MC or thrown object, search lockers.

Hey! So I tried it like this.

When I debug, this is what happens.

The player is still followed by the enemy, and I get TWO printed strings for seeing.
I can’t see that I’m missing anything here as of right now.

Well, when it is sensing the player, it should follow the player, and re-run that first line over and over and over, every time. When it doesn’t see the player is the only time the bottle should work.

If you want it to stop chasing the player, on the first line, put a “re-triggerable delay” node after the “Visible” printstring node. On that node, you’ll put in the time it should take for the enemy to stop chasing if it doesn’t see the player.

Then you need to make an event node to do the “notvisible” line. Here’s a mock-up going off of what I had in that test project

1 Like

This is what it looks like right now.

Following the player

Go to nearest locker

Code for catching and killing player


Okay so this is what everything looks like right now for reference. I have been doing stuff offline of course.
Sorry for the hassle, I’m kind of new to programming.

Hey @itsgoshi, sorry for the late reply.

I can see some things that could cause issue, but let’s touch base for a second. You are showing a good bit of code for reference- that’s great!

But what is working and what isn’t? :stuck_out_tongue:

When you change something, test it out and let us know what happens. :slight_smile:

Hello! It’s okay! I got to work on my menus in that time.
So many things are happening. I did add what you said. So one thing that happened is that the enemy just stops in front of doors.
When this happened I tried hiding in the nearest (I think?) locker, and somehow it gave me a game over screen.
:frowning:
I also saw it open a random one, but from the other side of the door. :skull:

I also get these


So the errors are due to “TargetLocker” not being set.

Part of why you’re running into a lot of issues is you’re trying to do everything all at once, you need to focus on one thing at a time, get it done, and move on! :slight_smile: It helps cut down on bugs to do things this way.

So, first we’ll tackle the door. Then the lockers.

Open your level and go to one of the doors, then press the “P” key on your keyboard. There should be a lot of green space. This is your navmesh render and shows you all of the walkable area for your AI. If there is a gap in it, that means the navmesh will not allow the AI to walk there, so look at the door frame and make sure it’s got green floor! :slight_smile: If it does not, we now know what the problem is and we can work on tackling it!

If it DOES have green floor, either your door is too small or your character is too large, likely.

Test that out and let’s get to work!

Okey! So I checked off “Can affect Navigation” To false on both the door frame and door. If the door is closed, the enemy literally just gets stuck running at the door itself in the corner

If it’s open. It will run through. Later I will add a code for the AI to Open the door too.

But yes. That’s one issue kind of solved.

1 Like