Why this dot product isn't working?

Following the behavior tree guide from epic games( https://docs.unrealengine.com/latest/INT/Engine/AI/BehaviorTrees/QuickStart/15/index.html )
on part 15 it gives exercises to make. One of them is to add a dot product to follow only if the AI is in front of the player.I don’t know a lot about this dot product but after a lot of attempts i was able to make the radius go only in front of the AI, but for some reason it is not updating the “front view” when the AI changes direction, it always stays on the same direction, or goes to the opposite direction.

The Aggro Check changes i’ve done:

What its looking like:

At first, you’re misunderstanding how the nodes of this blueprint are intended to work. The MultiSphereTraceForObjects is done to get all pawns within a radius around your AI pawn. You can understand the radius of this SphereTrace as the maximum vision range of your AI pawn. Or probably you understood this but you cannot change the radius of this SphereTrace so you would only be able to get a “vision cylinder” instead of the desired vision cone :smiley: Please revert the changes you’ve done to the SphereTrace and its inputs.

Now to the math part: The dot product gives you the length of a projection from one vector onto another. In the image |A|cos(Theta) is the dot product of A and B. It’s obviously dependent on the angle between those 2 vectors.

300px-Dot_Product.svg.png

Now to your problem: What you want to calculate is the angle between 2 vectors. You can get the angle between 2 vectors by normalizing both first. Afterwards taking the dot product of the 2 normalized vectors and at last taking the arcus cosinus (ACosD node in Blueprints) from the dot product.
The first vector is the ForwardVector of your AI pawn. The second one is a vector that points from your AI pawn to the pawn/actor your AI pawn wants to detect. (Most likely your ThirdPersonCharacter). Getting the first one is trivial. The second one you can get by subtracting the second vector from the first one. Now you want to check if the angle between those 2 vectors is smaller than a certain threshold (your vision angle). As you might guess a branch is what you want in front of your LineTrace (not the SphereTrace!).

Actor location is location, not a vector. You can think about actor location as vector from [0,0,0] to location.
Second thing is that dot product requires NORMALIZED vectors as input.
Result of dot product is cosine between 2 vectors, and you feed that as Y.