Enemy just won’t detect the player, it is also trying to go outside the map. I am just following a tutorial on youtube - https://youtu.be/4HoJIgyclZ4, I’ve been trying to solve this problem for almost a month now and check the code twice, thrice! But the problem persists please help me, I am getting sick of it and think that it is a bug in ue4 itself also note that I have around 60 enemies in the map, maybe that’s the problem. I have tried it with one enemy and with two enemies but it’s still the same!
This is the code for AI Sight Perception for the enemy:
void AEnemy::OnSensed(const TArray<AActor*>& UpdatedActors)
{
for (int i = 0; i < UpdatedActors.Num(); i++)
{
FActorPerceptionBlueprintInfo Info;
AIPerComp->GetActorsPerception(UpdatedActors[i], Info);
Well, I never used this feature and I haven’t watched the video either because it’s a 2h30 video.
But I’ll try to help anyways, just making a guess.
In your code you have:
Ok, I checked the video.
This is correct after all:
SetNewRotation(BaseLocation, GetActorLocation());
Forget what I said.
It will be very hard to help you with this problem. If the problem happens with a single enemy, debug the code to help you understand what is going on. But it’s important that you understand the code you are copying or else you will have a hard time. Usually guessing is not an option in this cases.
Maybe if I had your project files I could help.
If you need to get rotation between two vectors/points use UKismetMathLibrary::FindLookAtRotationdocs.unrealengine.com/…
Also, it’s hard to spot an error just by looking at the code. I’d recommend you to use your IDE debug tools or simple prints to watch variable values. If you need visual representation use DrawDebug…
For example, use DrawDebugLine to see where your vector is pointing or DrawDebugSphere to check coordinates.
Try testing your code only with one enemy on an empty level, it’s way easier to debug a single instance.
In addition
include “Components/BoxComponent.h” include “MonsterShooterCharacter.h” include “Perception/AIPerceptionComponent.h” include “Perception/AISenseConfig_Sight.h”
// Sets default values
AEnemy::AEnemy()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
// Called to bind functionality to input
void AEnemy::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
So what are you suggestion me to do? Should I follow the article which you’ve sent me? Also I’ve tried testing the same code on another empty level with one enemy, two enemies but still it doesn’t work.
Unfortunately, I cannot compile your code due to the external dependencies so You need to debug your code yourself.
So the mistake can be caused by these points:
You don’t check that UpdatedActors[i] == Player before moving. As the result, AI moves to the latest spotted pawn which is likely not the player if you have ~60 pawns
Your enemy is trying to leave the map because you tell him to do so in Tick().
But you did not tell him when to stop moving.
If these two things are not the problem, please describe what is exactly wrong and what behavior you are expecting. Also, it’d be nice if you could provide the link to the whole project so I can launch it on my computer.
The Problem I’m Facing:
The enemies mostly try to go outside the map through the corners of a map (square map), and around two enemies are inactive for some time then after about 10 seconds they also try to get outside the map through the corners. Another thing I have noticed is that they come back inside the maps through the walls and then some just fall down and die.
The Behavior I’m Expecting:
The behavior I’m expecting is that all the enemies should move towards the player and attack him (no animation or anything) so that the player’s health decreases, The player can also attack the enemies and kill them.
Well, I need your project files then to help you. At least I’ll be able to compile it.
Are you using some version control like Git?
Or you can just upload .rar file on google drive and share the link