Hello
I’d like to use CollisionSphere to move it to you when you enter the area.
Is there a problem with this code?
Why doesn’t it move? I’ve already checked everything else except the code.
Please help me…
void ABaseCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FindTarget(DeltaTime);
}
void ABaseCharacter::FindTarget(float time){
TArray<AActor*> CollectedActors;
SightSphere->GetOverlappingActors(CollectedActors);
int32 CollectedNum = CollectedActors.Num();
FVector toMonster;
for (int32 iCollected = 0; iCollected < CollectedNum; ++iCollected){
FVector monPos = CollectedActors[iCollected]->GetActorLocation();
FVector toMon = monPos - GetActorLocation();
DistanceToMon[iCollected] = toMon.Size();
toMonster /= DistanceToMon[iCollected];
FRotator toMonRotation = toMon.Rotation();
toMonRotation.Pitch = 0;
RootComponent->SetWorldRotation(toMonRotation);
AddMovementInput(toMonster, Speed * time);
}
}