I’m making a 2D Sprite platformer as a personal project. I have an enemy character that hurts the player when it overlaps a damage box with the player’s capsule (triggers the “ApplyDamage” method) and turns around when a collision box hits an actor other than the player/stops detecting the floor.
When I’m playing a “normal” level, these work as intended. However, when I place both actors (player and enemy) on a TileMap, the “ApplyDamage” method won’t trigger, and the “TurnAround” method will trigger both with the player and other actors.
Even though I only made changes to the map, I have no idea why it will not work. Any help would be appreciated.
//triggers when the enemy collides with a wall
void AEnemyPaperCharacter::WallDe
tectionEvent(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSwep,
const FHitResult& SweepResult)
{
TurnCharacter();
}
//when we end overlapping with floor, turn around
void AEnemyPaperCharacter::FloorDetectionEvent(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
TurnCharacter();
}
void AEnemyPaperCharacter::OnBeginColisionDamageEvent(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSwep, const FHitResult& SweepResult)
{
AController* EnemyController = GetInstigator()->GetController();
UGameplayStatics::ApplyDamage(OtherActor, DamageValue, EnemyController, this,
DamageType);
}
//set the actor rotation to 180° of the original
void AEnemyPaperCharacter::TurnCharacter()
{
FRotator Direction = GetActorRotation().Add(0.0f, 180.0f, 0.0f);
SetActorRotation(Direction);
}