void AGameplayAbilityWorldReticle::FaceTowardSource(bool bFaceIn2D) { if (TargetingActor) { if (bFaceIn2D) { FVector FacingVector = (TargetingActor->StartLocation.GetTargetingTransform().GetLocation() - GetActorLocation()).GetSafeNormal2D(); if (FacingVector.IsZero()) { FacingVector = -GetActorForwardVector().GetSafeNormal2D(); } if (!FacingVector.IsZero()) { SetActorRotation(FacingVector.Rotation()); } } else { FVector FacingVector = (TargetingActor->StartLocation.GetTargetingTransform().GetLocation() - GetActorLocation()).GetSafeNormal(); if (FacingVector.IsZero()) { FacingVector = -GetActorForwardVector().GetSafeNormal(); } SetActorRotation(FacingVector.Rotation()); } } }
void AGameplayAbilityTargetActor_Trace::AimWithPlayerController(const AActor* InSourceActor, FCollisionQueryParams Params, const FVector& TraceStart, FVector& OutTraceEnd, bool bIgnorePitch) const { if (!OwningAbility) // Server and launching client only { return; } APlayerController* PC = OwningAbility->GetCurrentActorInfo()->PlayerController.Get(); check(PC); FVector ViewStart; FRotator ViewRot; PC->GetPlayerViewPoint(ViewStart, ViewRot); const FVector ViewDir = ViewRot.Vector(); FVector ViewEnd = ViewStart + (ViewDir * MaxRange); ClipCameraRayToAbilityRange(ViewStart, ViewDir, TraceStart, MaxRange, ViewEnd); FHitResult HitResult; LineTraceWithFilter(HitResult, InSourceActor->GetWorld(), Filter, ViewStart, ViewEnd, TraceProfile.Name, Params); const bool bUseTraceResult = HitResult.bBlockingHit && (FVector::DistSquared(TraceStart, HitResult.Location) <= (MaxRange * MaxRange)); const FVector AdjustedEnd = (bUseTraceResult) ? HitResult.Location : ViewEnd; FVector AdjustedAimDir = (AdjustedEnd - TraceStart).GetSafeNormal(); if (AdjustedAimDir.IsZero()) { AdjustedAimDir = ViewDir; } if (!bTraceAffectsAimPitch && bUseTraceResult) { FVector OriginalAimDir = (ViewEnd - TraceStart).GetSafeNormal(); if (!OriginalAimDir.IsZero()) { // Convert to angles and use original pitch const FRotator OriginalAimRot = OriginalAimDir.Rotation(); FRotator AdjustedAimRot = AdjustedAimDir.Rotation(); AdjustedAimRot.Pitch = OriginalAimRot.Pitch; AdjustedAimDir = AdjustedAimRot.Vector(); } } OutTraceEnd = TraceStart + (AdjustedAimDir * MaxRange); }
float UEnvQueryGenerator_Donut::GetArcBisectorAngle(FEnvQueryInstance& QueryInstance) const { float BisectAngle = 0.0f; FVector Direction; if (bDefineArc) { if (ArcDirection.DirMode == EEnvDirection::TwoPoints) { TArray<FVector> Start; TArray<FVector> End; QueryInstance.PrepareContext(ArcDirection.LineFrom, Start); QueryInstance.PrepareContext(ArcDirection.LineTo, End); if (Start.Num() > 0 && End.Num() > 0) { const FVector LineDir = (End[0] - Start[0]).GetSafeNormal(); const FRotator LineRot = LineDir.Rotation(); BisectAngle = LineRot.Yaw; } } else { TArray<FRotator> Rot; QueryInstance.PrepareContext(ArcDirection.Rotation, Rot); if (Rot.Num() > 0) { BisectAngle = Rot[0].Yaw; } } } return BisectAngle; }
// Called every frame void AMonster::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); ARaiderCharacter *avatar = Cast<ARaiderCharacter>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0)); if (!avatar) return; FVector toPlayer = avatar->GetActorLocation() - GetActorLocation(); this->GetCharacterMovement()->bOrientRotationToMovement = true; // Rotate character to moving direction float distanceToPlayer = toPlayer.Size(); // If the player is not in the SightSphere of the monster, // go back if (distanceToPlayer > SightSphere->GetScaledSphereRadius()) { // If the player is out of sight, // then the enemy cannot chase return; } toPlayer /= distanceToPlayer; // normalizes the vector FRotator Rotation = toPlayer.Rotation(); const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X); AddMovementInput(Direction, m_fSpeed * DeltaTime); }
FVector2D AOrionPlaceableItem::GetAim(FVector WorldAim) { const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(WorldAim); const FRotator AimRotLS = AimDirLS.Rotation(); return FVector2D(AimRotLS.Yaw, AimRotLS.Pitch); }
void UMWBotSensorComponent::LookAt(const AActor* Actor, const FVector Point) { //if (bCrazy) //{ // return; //} // Convert aim direction to eye parent's local space FVector aimDirWS = Actor ? Actor->GetActorLocation() : Point; // world space aimDirWS -= GetComponentLocation(); FVector aimDirLS; // local space if (AttachParent) { // If attached to socket, use socket transform if (!AttachSocketName.IsNone()) { aimDirLS = AttachParent->GetSocketTransform(AttachSocketName, ERelativeTransformSpace::RTS_World).InverseTransformVectorNoScale(aimDirWS); } else { aimDirLS = AttachParent->GetComponentTransform().InverseTransformVectorNoScale(aimDirWS); } } else { aimDirLS = aimDirWS; } DesiredRotation = aimDirLS.Rotation(); }
void ATP_TwinStickPawn::FireShot(FVector FireDirection) { // If we it's ok to fire again if (bCanFire == true) { // If we are pressing fire stick in a direction if (FireDirection.SizeSquared() > 0.0f) { const FRotator FireRotation = FireDirection.Rotation(); // Spawn projectile at an offset from this pawn const FVector SpawnLocation = GetActorLocation() + FireRotation.RotateVector(GunOffset); UWorld* const World = GetWorld(); if (World != NULL) { // spawn the projectile World->SpawnActor<ATP_TwinStickProjectile>(SpawnLocation, FireRotation); } bCanFire = false; World->GetTimerManager().SetTimer(TimerHandle_ShotTimerExpired, this, &ATP_TwinStickPawn::ShotTimerExpired, FireRate); // try and play the sound if specified if (FireSound != nullptr) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } bCanFire = false; } } }
void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn) { // Look toward focus FVector FocalPoint = GetFocalPoint(); APawn* const Pawn = GetPawn(); if (Pawn) { FVector Direction = FAISystem::IsValidLocation(FocalPoint) ? (FocalPoint - Pawn->GetPawnViewLocation()) : Pawn->GetActorForwardVector(); FRotator NewControlRotation = Direction.Rotation(); // Don't pitch view unless looking at another pawn if (Cast<APawn>(GetFocusActor()) == nullptr) { NewControlRotation.Pitch = 0.f; } NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw); if (GetControlRotation().Equals(NewControlRotation, 1e-3f) == false) { SetControlRotation(NewControlRotation); if (bUpdatePawn) { Pawn->FaceRotation(NewControlRotation, DeltaTime); } } } }
// Render onto tt (using renderer) sitting @ cameraPos, // facing cameraDir, an object with radiusWorldUnits. void ATheHUD::RenderScreen( USceneCaptureComponent2D* renderer, FVector lookPos, float radiusWorldUnits, FVector cameraDir ) { UTextureRenderTarget2D* tt = renderer->TextureTarget; // http://stackoverflow.com/questions/3717226/ // radiusOnScreenPX = radiusWorldUnits*SW/(tan(fov / 2) * Z); // ZBack = radiusWorldUnits*SW/(tan( fovy / 2 )*radiusOnScreenPX) // Calculate Z distance back for a given pixel radius // Set particular render properties & render the screen // to texture in w. float D = GetZDistance( radiusWorldUnits, tt->GetSurfaceWidth(), tt->GetSurfaceHeight(), renderer->FOVAngle ); FVector eyePos = lookPos - cameraDir * D; FQuat quat = cameraDir.Rotation().Quaternion(); renderer->SetRelativeLocationAndRotation( eyePos, quat ); FVector2D screenSize = ui->gameChrome->gameCanvas->Size; screenSize.X -= ui->gameChrome->rightPanel->Size.X; FVector up = renderer->GetUpVector(); FLookAtMatrix lookAt( eyePos, lookPos, up ); FPerspectiveMatrix persp( rendererMinimap->FOVAngle/2.f, 1.f, 1.f, 0.5f ); FMatrix mvp1 = lookAt * persp; vector<Ray> rays = Game->pc->GetFrustumRays( FBox2DU( 0.f, 0.f, screenSize.X, screenSize.Y ) ); float zValue = lookPos.Z; FPlane plane( FVector(0.f, 0.f, 1.f), zValue ); vector<FVector> pts; for( int i = 0; i < rays.size(); i++ ) { FVector pt = FMath::LinePlaneIntersection( rays[i].start, rays[i].end, plane ); //Game->flycam->DrawDebug( pt, 25.f, FLinearColor::White, .25f ); pts.push_back( pt ); } //FLinearColor Cyan(0,1,1,1); //for( int i = 0; i < pts.size() - 1; i++ ) //{ // Game->flycam->DrawDebug( pts[i], pts[i+1], 25.f, Cyan, .25f ); //} //if( pts.size() > 1 ) //{ // Game->flycam->DrawDebug( pts[pts.size()-1], pts[0], 25.f, Cyan, .25f ); //} ui->gameChrome->rightPanel->minimap->pts.clear(); FVector2D minimapSize = ui->gameChrome->rightPanel->minimap->Size; for( int i = 0; i < pts.size(); i++ ) { FVector4 transformedPt = mvp1.TransformPosition( pts[i] ); float div = transformedPt.W; transformedPt /= FVector4( div, div, div, div ); FVector2D p( transformedPt.X, transformedPt.Y ); // between [-1,1] p *= 4.f/3.f; //!! Multiplying P by 4./3 req'd.. double-check p *= minimapSize/2.f; p.Y *= -1.f; p += minimapSize/2.f; p += ui->gameChrome->rightPanel->minimap->GetAbsPos(); ui->gameChrome->rightPanel->minimap->pts.push_back( p ); } }
void ATP_TopDownCharacter::Tick(float DeltaSeconds) { if (CursorToWorld != nullptr) { if (UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled()) { if (UWorld* World = GetWorld()) { FHitResult HitResult; FCollisionQueryParams Params; FVector StartLocation = TopDownCameraComponent->GetComponentLocation(); FVector EndLocation = TopDownCameraComponent->GetComponentRotation().Vector() * 2000.0f; Params.AddIgnoredActor(this); World->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, Params); FQuat SurfaceRotation = HitResult.ImpactNormal.ToOrientationRotator().Quaternion(); CursorToWorld->SetWorldLocationAndRotation(HitResult.Location, SurfaceRotation); } } else if (APlayerController* PC = Cast<APlayerController>(GetController())) { FHitResult TraceHitResult; PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult); FVector CursorFV = TraceHitResult.ImpactNormal; FRotator CursorR = CursorFV.Rotation(); CursorToWorld->SetWorldLocation(TraceHitResult.Location); CursorToWorld->SetWorldRotation(CursorR); } } }
void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection) { auto BarrelRotator = Barrel->GetForwardVector().Rotation(); auto AimAsRotator = AimDirection.Rotation(); auto DeltaRotator = AimAsRotator - BarrelRotator; Barrel->Elevate(DeltaRotator.Pitch); }
void AZombieShooterCharacter::CalculateFacing() { // Rotate character towards the mouse pointer FVector PlaneNormal; PlaneNormal.X = 0.f; PlaneNormal.Y = 0.f; PlaneNormal.Z = 1.f; FVector PlanePoint = GetActorLocation(); float PlaneFormulaD = -1 * (PlaneNormal.X * PlanePoint.X + PlaneNormal.Y * PlanePoint.Y + PlaneNormal.Z * PlanePoint.Z); // Calculate our t to calculate coordinates: float tLeftSide = PlaneNormal.X*WorldDirection.X + PlaneNormal.Y*WorldDirection.Y + PlaneNormal.Z*WorldDirection.Z; float tRightSide = -1 * (PlaneFormulaD + PlaneNormal.X*WorldLocation.X + PlaneNormal.Y*WorldLocation.Y + PlaneNormal.Z*WorldLocation.Z); float t = tRightSide / tLeftSide; FVector IntersectionPoint; // The result point where the mouse cursor is "projected". This is the point at which the pawn will be looking at. IntersectionPoint.X = t * WorldDirection.X + WorldLocation.X; IntersectionPoint.Y = t * WorldDirection.Y + WorldLocation.Y; IntersectionPoint.Z = t * WorldDirection.Z + WorldLocation.Z; FVector Direction = IntersectionPoint - PlanePoint; FRotator NewControlRotation = Direction.Rotation(); NewControlRotation.Pitch = 0.f; NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw); NewControlRotation.Roll = 0.f; Rotation = NewControlRotation; ChangeFacing(Rotation); }
void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn) { // Look toward focus FVector FocalPoint = GetFocalPoint(); if( !FocalPoint.IsZero() && GetPawn()) { FVector Direction = FocalPoint - GetPawn()->GetActorLocation(); FRotator NewControlRotation = Direction.Rotation(); // Don't pitch view of walking pawns unless looking at another pawn if ( GetPawn()->GetMovementComponent() && GetPawn()->GetMovementComponent()->IsMovingOnGround() && PathFollowingComponent && (!PathFollowingComponent->GetMoveGoal() || !Cast<APawn>(PathFollowingComponent->GetMoveGoal()) ) ) { NewControlRotation.Pitch = 0.f; } NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw); SetControlRotation(NewControlRotation); APawn* const P = GetPawn(); if (P && bUpdatePawn) { P->FaceRotation(NewControlRotation, DeltaTime); } } }
void AVehiclePawn::ReceiveHit(class UPrimitiveComponent* MyComp, class AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalForce, const FHitResult& Hit) { Super::ReceiveHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalForce, Hit); if (ImpactTemplate && NormalForce.Size() > ImpactEffectNormalForceThreshold) { AVehicleImpactEffect* EffectActor = GetWorld()->SpawnActorDeferred<AVehicleImpactEffect>(ImpactTemplate, HitLocation, HitNormal.Rotation()); if (EffectActor) { float DotBetweenHitAndUpRotation = FVector::DotProduct(HitNormal, GetMesh()->GetUpVector()); EffectActor->HitSurface = Hit; EffectActor->HitForce = NormalForce; EffectActor->bWheelLand = DotBetweenHitAndUpRotation > 0.8; UGameplayStatics::FinishSpawningActor(EffectActor, FTransform(HitNormal.Rotation(), HitLocation)); } } if (ImpactCameraShake) { AVehiclePlayerController* PC = Cast<AVehiclePlayerController>(Controller); if (PC != NULL && PC->IsLocalController()) { PC->ClientPlayCameraShake(ImpactCameraShake, 1); } } }
void ATP_TwinStickPawn::Tick(float DeltaSeconds) { // Find movement direction const float ForwardValue = GetInputAxisValue(MoveForwardBinding); const float RightValue = GetInputAxisValue(MoveRightBinding); // Clamp max size so that (X=1, Y=1) doesn't cause faster movement in diagonal directions const FVector MoveDirection = FVector(ForwardValue, RightValue, 0.f).GetClampedToMaxSize(1.0f); // Calculate movement const FVector Movement = MoveDirection * MoveSpeed * DeltaSeconds; // If non-zero size, move this actor if (Movement.SizeSquared() > 0.0f) { const FRotator NewRotation = Movement.Rotation(); FHitResult Hit(1.f); RootComponent->MoveComponent(Movement, NewRotation, true, &Hit); if (Hit.IsValidBlockingHit()) { const FVector Normal2D = Hit.Normal.GetSafeNormal2D(); const FVector Deflection = FVector::VectorPlaneProject(Movement, Normal2D) * (1.f - Hit.Time); RootComponent->MoveComponent(Deflection, NewRotation, true); } } // Create fire direction vector const float FireForwardValue = GetInputAxisValue(FireForwardBinding); const float FireRightValue = GetInputAxisValue(FireRightBinding); const FVector FireDirection = FVector(FireForwardValue, FireRightValue, 0.f); // Try and fire a shot FireShot(FireDirection); }
FRotator ANimModCharacter::GetAimOffsets() const { const FVector AimDirWS = GetBaseAimRotation().Vector(); const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(AimDirWS); const FRotator AimRotLS = AimDirLS.Rotation(); return AimRotLS; }
void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection) { auto BarrelRotator = Barrel->GetForwardVector().Rotation(); auto AimDirectionAsRotator = AimDirection.Rotation(); //UE_LOG(LogTemp, Warning, TEXT("Aim direction as rotator: %s"), *AimDirectionAsRotator.ToString()) auto DeltaRotator = AimDirectionAsRotator - BarrelRotator; Barrel->Elevate(DeltaRotator.Pitch); if (Turret) { Turret->Rotate(DeltaRotator.Yaw); } }
void UTankAimingComponent::MoveBarrelTowards(FVector aimDirection) { // Work-out difference between current barrel rotation and aimDirection FRotator barrelRotator = barrel->GetForwardVector().Rotation(); FRotator aimAsRotator = aimDirection.Rotation(); FRotator deltaRotator = aimAsRotator - barrelRotator; //UE_LOG(LogTemp, Warning, TEXT("deltaRotator is %f"), deltaRotator.Pitch); barrel->Elevate(deltaRotator.Pitch); //TODO remove magic number }
void UEnemyRoadSplineComponent::MoveCharacterlongSplineTrack(ACharacter* Actor) { if (RoadSpline) { FVector DirectionToRun = RoadSpline->CalDirectionToRun(Actor, this); DirectionToRun.Normalize(); DirectionToRun.Z = 0; Actor->AddMovementInput(DirectionToRun, 10); SetActorRotationMulticast(DirectionToRun.Rotation()); } }
void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection) { auto BarrelRotation = Barrel->GetForwardVector().Rotation(); auto AimAtRotation = AimDirection.Rotation(); auto DeltaRotation = AimAtRotation - BarrelRotation; UE_LOG(LogTemp, Warning, TEXT("AimAtRotation: %s"), *AimAtRotation.ToString()); UE_LOG(LogTemp, Warning, TEXT("BarrelRotation: %s"), *DeltaRotation.ToString()); Barrel->Elevate(DeltaRotation.Pitch); Turret->Rotate(DeltaRotation.Yaw); }
void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection) { if (!Barrel || !Turret) { return; } // Work-out difference between current barrel roation, and AimDirection auto BarrelRotator = Barrel->GetForwardVector().Rotation(); auto AimAsRotator = AimDirection.Rotation(); auto DeltaRotator = AimAsRotator - BarrelRotator; Barrel->Elevate(DeltaRotator.Pitch); Turret->Rotate(DeltaRotator.Yaw); }
void AGameObject::Face( FVector point ) { if( Dead ) { error( "Face dead unit" ); return; } FVector to = point - Pos; if( float len = to.Size() ) { to /= len; SetRot( to.Rotation() ); } }
void AGOAPerCharacter::Tick(float DeltaSeconds) { if (CursorToWorld != nullptr) { if (APlayerController* PC = Cast<APlayerController>(GetController())) { FHitResult TraceHitResult; PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult); FVector CursorFV = TraceHitResult.ImpactNormal; FRotator CursorR = CursorFV.Rotation(); CursorToWorld->SetWorldLocation(TraceHitResult.Location); CursorToWorld->SetWorldRotation(CursorR); } } }
void AHunterProjectile::MoveInDirection(const FVector &direction) { m_velocity = direction * m_projectileVelocity; USceneComponent *hopefullySprite = GetRootComponent()->GetChildComponent(0); if (hopefullySprite != nullptr) { FRotator thisRotation = hopefullySprite->RelativeRotation; FRotator directionRotator = direction.Rotation(); thisRotation.Yaw = directionRotator.Yaw; hopefullySprite->SetRelativeRotation(thisRotation); } }
void ALMPlayerController::PawnRotationToTarget() { if (this->bIsRotationChange) { FHitResult CursorHitRes = FHitResult(); if (GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, false, CursorHitRes)) { FVector FaceDir = CursorHitRes.Location - GetPawn()->GetActorLocation(); FRotator FaceRotator = FaceDir.Rotation(); FaceRotator.Pitch = 0; FaceRotator.Roll = 0; GetPawn()->SetActorRotation(FaceRotator); } } }
void UTankAimingComponent::MoveTurretTowards(FVector aimDirection) { FRotator turretRotator = turret->GetForwardVector().Rotation(); FRotator aimAsRotator = aimDirection.Rotation(); FRotator deltaRotator = aimAsRotator - turretRotator; //UE_LOG(LogTemp, Warning, TEXT("deltaRotator is %f"), deltaRotator.Yaw); if (FMath::Abs(deltaRotator.Yaw) < 180) { //float newRotatorDirection = -(360 - deltaRotator.Yaw); turret->Rotate(deltaRotator.Yaw); } else { turret->Rotate(-deltaRotator.Yaw); } }
void ASkillHintActor::UpdatePos(FVector PlayerPos, FVector MousePos) { FVector dir = MousePos - PlayerPos; dir.Z = 0; float len = dir.Size(); dir.Normalize(); switch(SkillType) { case ESkillHintEnum::DirectionSkill: case ESkillHintEnum::DirectionSkill_CanBlock: { SetActorRotation(dir.Rotation()); SetActorLocation(PlayerPos); if (len < MinimalLength) { len = MinimalLength; } else if (len > SkillLength) { len = SkillLength; } if(!IsFixdLength) { SkillLength = len; SkillPos = MousePos; } } break; case ESkillHintEnum::RangeSkill: { if (len < MinimalCastRadius) { len = MinimalCastRadius; } else if (len > SkillCastRadius) { len = SkillCastRadius; } FVector pos = dir*len + PlayerPos; SetActorLocation(pos); } break; } UpdateLength(); }
void UTankAimingComponent::MoveBarrelTowards(const FVector& AimDirection) { if (IsInitialised()) { const FRotator AimAsRotator = AimDirection.Rotation(); const FRotator BarrelRotator = Barrel->GetForwardVector().Rotation(); const FRotator BarrelDeltaRotator = AimAsRotator - BarrelRotator; float BarrelDeltaElevate = FMath::UnwindDegrees(BarrelDeltaRotator.Pitch); const FRotator TurretRotator = Turret->GetForwardVector().Rotation(); const FRotator TurretDeltaRotator = AimAsRotator - TurretRotator; float TurretDeltaRotate = FMath::UnwindDegrees(TurretDeltaRotator.Yaw); Barrel->Elevate(BarrelDeltaElevate); Turret->Rotate(TurretDeltaRotate); } }
void UTankAimingComponent::MoveWeaponTowards(FVector AimDirection) { if (!ensure(Barrel) || !ensure(Turret)) { return; } // Work out difference between current barrel rotation and aimdirection auto BarrelRotator = Barrel->GetForwardVector().Rotation(); auto AimAsRotator = AimDirection.Rotation(); auto DeltaRotator = AimAsRotator - BarrelRotator; Barrel->Elevate(DeltaRotator.Pitch); if (FMath::Abs(DeltaRotator.Yaw) < 180) { Turret->Rotate(DeltaRotator.Yaw); } else { Turret->Rotate(-DeltaRotator.Yaw); } }
//Bearing mode void APawnWithCamera::BearingMode() { //Message to indicate bearing mode has been activated GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("STARTING BEARING MODE!"))); //Trigger turning and zooming when bearing mode is activated turnToSun = true; FVector VoyagerLocation = GetActorLocation(); FVector NewRotationLocation = SphereVisualLocation - VoyagerLocation; NewRotation = NewRotationLocation.Rotation(); bZoomingIn = true; //How to get half the original distance for zoom OrigDist = FVector::Dist(SphereVisualLocation, GetActorLocation()); MidPoint.X = (SphereVisualLocation.X + GetActorLocation().X ) / 2; MidPoint.Y = (SphereVisualLocation.Y + GetActorLocation().Y ) / 2; MidPoint.Z = (SphereVisualLocation.Z + GetActorLocation().Z ) / 2; }