hi, playing around unreal , i am stuck in process of casting, basically i have a playercontroller class(character) through which i am raycasting to hit a turretclass(pawn), however
PlayerController.cpp
AActor* hitActor = hit.GetActor();
if (hitActor)
{
UE_LOG(LogTemp, Warning, TEXT("hit object name %s"), *(hitActor->GetName()));
if (hitActor->ActorHasTag("Turret"))
{
//ERROR HAPPENS HERE
/*ATurret* turret = Cast<ATurret>(hitActor);
if (turret)
{
turret->TakeDamage(10);
UE_LOG(LogTemp, Warning, TEXT("damaged object name %s"), *(hitActor->GetName()));
}*/
}
}
2nd question: i am trying to rotate turret towards player location in range, i am able to set bool when player is in range but however, i need to know how to rotate it, i tried FINDLOOKATROTATION() but i dont see an example to use it on c++
3rd how to decide if i must create an actor or pawn class, or make an component class? lets say i am making a game with bots and pick items, for now i have set pick up items have an actorcomponent script, i have made turret using pawn class(should i have made it using actor class?), its quite confusing atm.
In the Game Framework’s logic Pawn (along with Pawn-derived classes like Character) is something that can be possessed by a Controller. Therefore if your game does allow your players and/or bots to control turrets then your turret should be a Pawn. If your turret is just a level object to be destroyed then it should be an Actor.
And about Components: you can create multiple reusable Components for your Pawns/Characters and then create multiple Pawn- or Character-derived classes that combine different sets of these Components. Think of a Component as of an ability or property of an actor and think of Pawn-derived classes as of different kinds of Pawns.
myActor->SetActorHiddenInGame(true);
// Disables collision components
myActor->SetActorEnableCollision(false);
// Stops the Actor from ticking
myActor->SetActorTickEnabled(false);
removing myactor reference solved the bug, it seems assigning myActor = GetOwner(); doesnt do anything, also i am trying to use Findlookatrotation through blueprint it ends up crashing aswell…