FG Project 1

Nim

4 Week long game project in 3D using Unreal Engine 4, with students at FutureGames.
As a 'Game Programmer' I worked on a system for targeting important object in the world.
Which involed raycasting and checking if objects was in the players viewport.

Targeting Ray
                
void ACPP_Character::TargetingRay()
{
    FVector EndPoint = (Camera->GetForwardVector() * TargetRange) + Camera->GetComponentLocation();
     
    if ((UKismetSystemLibrary::LineTraceSingle(GetWorld(), Camera->GetComponentLocation(), EndPoint, UEngineTypes::ConvertToTraceType(ECC_Target),
                    false, ActorsToIgnore, EDrawDebugTrace::None, OutHit, false, FColor::Green, FColor::Red, 2f)))
                    {
                        FollowCameraVec = PlayerMesh->GetForwardVector();
                        FollowCameraPos = Camera->GetComponentLocation();
                        ActorPosition = OutHit.GetActor()->GetActorLocation();
                        CheckInView = (ActorPosition - FollowCameraPos); CheckInView.Normalize();
                        ActorBehindCamera = FVector::DotProduct(FollowCameraVec, CheckInView);

                        bIsHit = true;
                    } else { bIsHit = false; }
}
                    
                    
Locking To Target
                
void ACPP_Character::LockingToTarget()
{
    if (bLockedOnTarget)
    {
        FRotator CameraLookRotation = UKismetMathLibrary::FindLookAtRotation(Camera->GetComponentLocation(), CurrentTargetableActor->GetActorLocation());
        FRotator PlayerLookRotation = UKismetMathLibrary::FindLookAtRotation(GetActorLocation(), CurrentTargetableActor->GetActorLocation());

        SetActorRotation(UKismetMathLibrary::MakeRotator(0, 0, PlayerLookRotation.Yaw));
        PlayerMesh->SetWorldRotation(FRotator(0, PlayerLookRotation.Yaw, 0));
        CameraBoom->SetWorldRotation(FRotator(CameraLookRotation.Pitch, PlayerLookRotation.Yaw - 2f, 0));

        if (CurrentTargetAbleActor->GetDistance(this) > TargetRange)
        {
            UnTargetActor();
        }                   
}                  
                    
                    
Get Closest Actor

AActor* ACPP_Character::GetClosestActor()
{
    float ActorDistance = TNumericLimits::Max();
    AActor* ActorToReturn = nullptr;

    for (AActor* Actor : TargetableActorsArray)
    {
        float Distance = FVector::DistSquared(GetActorLocation(), Actor->GetActorLocation());

        if (Distance < ActorDistance && Actor != CurrentTargetableActor)
        {
            ActorDistance = Distance;
            ActorToReturn = Actor;
        }
    }
    return ActorToReturn;
}