How to set the AI perception "eyes" location?

I’m working on a tower defense game and using AI Perception on the tower controller.

The problem is that the AI perception component can’t be attached to another component and doesn’t seems to have any “eye location” settings and it seems to use the controller origin.

The tower pawn origin is on the ground so it’s the same for the controller and AI perception. This mean that my tower “eyes” are on the ground instead of being on the top of the tower.
How can I make my AI perception component to trace from the top of the tower and not the ground? (I CAN’T change the origin of the tower because I need it to be on the ground to place them when the player builds it)

You could attach a cone shaped geometry to the character as it’s vision radius/distance. Use that as part of your perception checks.

It is fairly easy to change the location that the AI perception uses as the source of the sight sense in C++. You need a custom character class and then override GetActorEyesViewPoint.
I often use a custom socket that I can add or move on any character and set that as the location:

In the cpp file:

void ABase_Game_Character::GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const
{
	Location = GetMesh()->GetSocketLocation("AI_EYES");
	Rotation = GetMesh()->GetSocketRotation("AI_EYES");
}

and in the header:

	//Override for AI Perception "Eye" Location
	void GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const override;

See this post for more details:

3 Likes

Hi, actually, there is an eye height setting even within Blueprint. Open the actor which will be possessed by the AI controller, go to the class defaults and look under the camera rollout: “Base eye height”

4 Likes

Eye height is not used by AI perception, changing that setting will have no effect on this.
The original function uses the location and rotation for the actor.

void AActor::GetActorEyesViewPoint( FVector& OutLocation, FRotator& OutRotation ) const
{
OutLocation = GetActorLocation();
OutRotation = GetActorRotation();
}

That is not correct, I have tested this yesterday, and eye height does have an effect. Similar to Haories, I had a large actor with its root being below the ground, and hence, the sight sense did not register anything (I checked it with the AI debugger). But once I increased eye height, it worked, the debugger showed the visibility cone and all the markers. I am 4.19, launcher.

You’re right. Eye height adds an offset to the Z used in one of the functions and does do what you’ve described.

That’s great, thanks! It works nicely for the “origin” of the AI perception. Now is there a similar setting in Blueprint to offset the “destination” of the AI perception?

Hey @SeithCG! You may want to make a new post for this, these folks may not be around to answer you, and it’s enough to be a new topic! :slight_smile:
@Haoris, did you get your question answered, so I may mark this thread solved?

1 Like