void ALMPlayerController::RMouseDownSelectTarget() { FHitResult HitRes = FHitResult(); TArray<TEnumAsByte<EObjectTypeQuery>> ObjectType; //只检测一下对象 ObjectType.Add(EOBJECTTYPEQUERY_SELECTACTOR); if (GetHitResultUnderCursorForObjects(ObjectType,false,HitRes)) { if (HitRes.GetComponent() == pCurSelectedComponent) { return; } else { if (pCurSelectedComponent != nullptr) pCurSelectedComponent->SetRenderCustomDepth(false); pCurSelectedComponent = HitRes.GetComponent(); pCurSelectedComponent->SetRenderCustomDepth(true); } } }
void UGAAbilityBase::InitAbility() { //still want to initialize, as Spec is used in multiple places. DefaultContext = UGABlueprintLibrary::MakeContext(this, POwner, AvatarActor, this, FHitResult(ForceInit)).GetRef(); ActivationEffect.InitializeIfNotInitialized(POwner, this); CooldownEffect.InitializeIfNotInitialized(POwner, this); for (int32 Idx = 0; Idx < AttributeCost.Num(); Idx++) { AttributeCost[Idx].InitializeIfNotInitialized(POwner, this); } AttributeCostHandle.AddZeroed(AttributeCost.Num()); for (int32 Idx = 0; Idx < AbilityAttributeCost.Num(); Idx++) { AbilityAttributeCost[Idx].InitializeIfNotInitialized(POwner, this); } AbilityAttributeCostHandle.AddZeroed(AbilityAttributeCost.Num()); if (AbilityComponent) { World = AbilityComponent->GetWorld(); } if (!AbilityComponent) { AbilityComponent = GetAbilityComp(); } if (GetAttributes()) { GetAttributes()->InitializeAttributes(GetAbilityComp()); GetAttributes()->InitializeAttributesFromTable(); } ENetRole role = AbilityComponent->GetOwnerRole(); ENetMode mode = AbilityComponent->GetOwner()->GetNetMode(); { FAFOnAttributeReady Delegate = FAFOnAttributeReady::CreateUObject(this, &UGAAbilityBase::OnAttributeSetReplicated); AbilityComponent->RepAttributes.RegisterAttributeRepEvent(AbilityTag, Delegate); } //AbilityComponent->RepAttributes.AttributeMap.Add(AbilityTag, Attributes); if (role == ENetRole::ROLE_Authority || mode == ENetMode::NM_Standalone) { if (AbilityComponent && GetAttributes()) { UGAAttributesBase* NewAttributes = AbilityComponent->AddAddtionalAttributes(AbilityTag, GetAttributes());; SetAttributes(nullptr); SetAttributes(NewAttributes); } } if (!OwnerCamera) { OwnerCamera = POwner->FindComponentByClass<UCameraComponent>(); } OnAbilityInited(); }
bool ASwoim::TraceAhead(const FVector& Start, const FVector& End, UWorld* World, FHitResult& HitOut) { if (!World) { return false; } bool ReturnPhysMat = false; FCollisionQueryParams TraceParams(FName(TEXT("VictoreCore Trace")), true, this); TraceParams.bTraceComplex = true; TraceParams.bReturnPhysicalMaterial = ReturnPhysMat; TraceParams.AddIgnoredActor(this); ECollisionChannel CollisionChannel = ECollisionChannel::ECC_WorldStatic; //Re-initialize hit info HitOut = FHitResult(ForceInit); //Trace! World->LineTraceSingleByChannel( HitOut, //result Start, //start End, //end CollisionChannel, //collision channel TraceParams ); //Hit any Actor? return (HitOut.GetActor() != NULL); }
FHitResult UAbilitySystemBlueprintLibrary::GetHitResult(FGameplayCueParameters Parameters) { if (Parameters.EffectContext.GetHitResult()) { return *Parameters.EffectContext.GetHitResult(); } return FHitResult(); }
FHitResult UAbilitySystemBlueprintLibrary::EffectContextGetHitResult(FGameplayEffectContextHandle EffectContext) { if (EffectContext.GetHitResult()) { return *EffectContext.GetHitResult(); } return FHitResult(); }
bool UAirBlueprintLib::GetObstacle(const AActor* actor, const FVector& start, const FVector& end, FHitResult& hit, const AActor* ignore_actor, ECollisionChannel collision_channel) { hit = FHitResult(ForceInit); FCollisionQueryParams trace_params; trace_params.AddIgnoredActor(actor); if (ignore_actor != nullptr) trace_params.AddIgnoredActor(ignore_actor); return actor->GetWorld()->LineTraceSingleByChannel(hit, start, end, collision_channel, trace_params); }
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); } } }
FHitResult UAbilitySystemBlueprintLibrary::GetHitResultFromTargetData(FGameplayAbilityTargetDataHandle TargetData, int32 Index) { if (TargetData.Data.IsValidIndex(Index)) { FGameplayAbilityTargetData* Data = TargetData.Data[Index].Get(); if (Data) { const FHitResult* HitResultPtr = Data->GetHitResult(); if (HitResultPtr) { return *HitResultPtr; } } } return FHitResult(); }
FHitResult APlayerControl::RayPickSingle( const Ray& ray, SetAGameObject AcceptedTypes, SetAGameObject NotTypes ) { TArray<FHitResult> hits; FCollisionQueryParams fcqp( true ); // Returns closest blocking hit, checking all objects GetWorld()->LineTraceMultiByProfile( hits, ray.start, ray.end, "RayCast", fcqp ); // You get the first result. for( int i = 0; i < hits.Num(); i++ ) { if( AGameObject* go = Filter( hits[i].GetActor(), AcceptedTypes, NotTypes ) ) { return hits[i]; } } return FHitResult(); }
// Activate Overlap detection void AItemPickup::ActivatePickupOverlap() { // Check if Any Player is Within the range to pickup this actor if (Role >= ROLE_Authority) { for (TActorIterator<ARadePlayer> RadeActorItr(GetWorld()); RadeActorItr; ++RadeActorItr) { if (RadeActorItr && TriggerSphere && FVector::Dist(RadeActorItr->GetActorLocation(), GetActorLocation()) < TriggerSphere->GetUnscaledSphereRadius()) { OnBeginOverlap(nullptr,*RadeActorItr, nullptr, 0, false, FHitResult()); return; } } } // Enable Overlap Component TriggerSphere->OnComponentBeginOverlap.AddDynamic(this, &AItemPickup::OnBeginOverlap); TriggerSphere->OnComponentEndOverlap.AddDynamic(this, &AItemPickup::OnEndOverlap); }
// Called at the beginning of game-play. [11/12/2015 Matthew Woolley] void ARoadFeverCameraSystem::BeginPlay() { Super::BeginPlay(); // Get the camera's position. [11/12/2015 Matthew Woolley] CameraPosition.Location = EditorCameraReference->GetComponentLocation(); CameraPosition.Rotation = EditorCameraReference->GetComponentRotation(); // Destroy the camera so that the game doesn't keep rendering un-needed scenes. [11/12/2015 Matthew Woolley] EditorCameraReference->DestroyComponent(); if ( bIsPrimaryCamera ) { ARoadFeverCharacterNed* PlayerCharacter = Cast<ARoadFeverCharacterNed>( GetWorld()->GetFirstPlayerController()->GetPawn() ); OnActorEnter( PlayerCharacter->GetCameraDummy(), nullptr, 0, false, FHitResult() ); // Set the camera's position. [11/12/2015 Matthew Woolley] PlayerCharacter->CharactersCamera->SetWorldLocation( CameraPosition.Location ); PlayerCharacter->CharactersCamera->SetWorldRotation( CameraPosition.Rotation ); } else { SetActorTickEnabled( false ); } }
// Called every frame void AMyCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); //Draw a straight line in front of our character Start = MyCharacterCamera->GetComponentLocation(); End = Start + MyCharacterCamera->GetForwardVector()*MaxGraspLength; HitObject = FHitResult(ForceInit); GetWorld()->LineTraceSingleByChannel(HitObject, Start, End, ECC_Pawn, TraceParams); //Mouse hovered behaviour with an empty hand if (!SelectedObject) { //Turn off the highlight effect when changing to another actor if (HighlightedActor && HitObject.GetActor() != HighlightedActor) { GetStaticMesh(HighlightedActor)->SetRenderCustomDepth(false); HighlightedActor = nullptr; } //Check if there is an object blocking the hit and if it is in our hand's range if (HitObject.bBlockingHit && HitObject.Distance < MaxGraspLength) { //Check if the object has interractive behaviour enabled if (AssetStateMap.Contains(HitObject.GetActor()) || AssetStateMap.Contains(HitObject.GetActor()->GetAttachParentActor()) || ItemMap.Contains(HitObject.GetActor())) { HighlightedActor = HitObject.GetActor(); GetStaticMesh(HighlightedActor)->SetRenderCustomDepth(true); } } } //Behaviour for selected object in hand else { //Turn off the highlight effect because we can't pick up with this hand. if (HighlightedActor && HighlightedActor) { GetStaticMesh(HighlightedActor)->SetRenderCustomDepth(false); HighlightedActor = nullptr; } //Enable the player to access rotation mode bRotationModeAllowed = true; } //Draw object from the right hand if (RightHandSlot) { RightHandSlot->SetActorRotation(RightHandRotator + FRotator(0.f, GetActorRotation().Yaw, 0.f)); GetStaticMesh(RightHandSlot)->SetWorldLocation(GetActorLocation() + FVector(20.f, 20.f, 20.f) * GetActorForwardVector() + FVector(RightYPos, RightYPos, RightYPos) * GetActorRightVector() + FVector(0.f, 0.f, RightZPos)); //Add highlight if it is selected if (SelectedObject == RightHandSlot) { GetStaticMesh(RightHandSlot)->SetRenderCustomDepth(true); } else { GetStaticMesh(RightHandSlot)->SetRenderCustomDepth(false); } } //Draw object from the left hand if (LeftHandSlot) { LeftHandSlot->SetActorRotation(LeftHandRotator + FRotator(0.f, GetActorRotation().Yaw, 0.f)); GetStaticMesh(LeftHandSlot)->SetWorldLocation(GetActorLocation() + FVector(20.f, 20.f, 20.f) * GetActorForwardVector() - FVector(LeftYPos, LeftYPos, LeftYPos) * GetActorRightVector() + FVector(0.f, 0.f, LeftZPos)); //Add highlight if it is selected if (SelectedObject == LeftHandSlot) { GetStaticMesh(LeftHandSlot)->SetRenderCustomDepth(true); } else { GetStaticMesh(LeftHandSlot)->SetRenderCustomDepth(false); } } //Draw the stack held in hands if there is one if (TwoHandSlot.Num()) { float LastItemOldZ = 0; float ZOffset = 0; for (AActor* StackItem : TwoHandSlot) { if (LastItemOldZ) { ZOffset += StackItem->GetActorLocation().Z - LastItemOldZ; } LastItemOldZ = StackItem->GetActorLocation().Z; StackItem->SetActorRotation(FRotator(0.f, GetActorRotation().Yaw, 0.f)); GetStaticMesh(StackItem)->SetWorldLocation(GetActorLocation() + FVector(8.f, 8.f, 8.f) * GetActorForwardVector() + FVector(0.f, 0.f, 20.f + ZOffset)); } //Add highlight if it is selected if (TwoHandSlot.Contains(SelectedObject)) { GetStaticMesh(SelectedObject)->SetRenderCustomDepth(true); } else { GetStaticMesh(SelectedObject)->SetRenderCustomDepth(false); } } }
ASpaceRocksPawn::ASpaceRocksPawn(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { // Structure to hold one-time initialization - i.e. load all the Player's craft meshes etc. struct FConstructorStatics { ConstructorHelpers::FObjectFinderOptional<UStaticMesh> PlaneMesh; ConstructorHelpers::FObjectFinderOptional<UStaticMesh> ShieldMesh; FConstructorStatics() : PlaneMesh(TEXT("StaticMesh'/Game/SpaceRocks/StaticMeshes/PlayerCraft/UFO.UFO'")) , ShieldMesh(TEXT("StaticMesh'/Game/SpaceRocks/StaticMeshes/PlayerCraft/Shield.Shield'")) { } }; static FConstructorStatics ConstructorStatics; // ** Let's Build the player's craft ** // Firstly, the defence shield static mesh. This will normally not be visible (unless damage/crash/etc), but will form our root component. ShieldMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("ShieldMesh00")); ShieldMesh->SetStaticMesh(ConstructorStatics.ShieldMesh.Get()); RootComponent = ShieldMesh; // Turn on physics for static mesh - how cool is this! Craft will be subject to world physics (e.g. fall due to gravity etc) ShieldMesh->SetSimulatePhysics(false); ShieldMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); // Next, create Next, the static mesh component for the Craft itself and attach to root PlaneMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PlaneMesh0")); PlaneMesh->SetStaticMesh(ConstructorStatics.PlaneMesh.Get()); PlaneMesh->AttachTo(RootComponent); PlaneMesh->SetSimulatePhysics(false); // Note we are turning off physics/collision for this mesh - Handled instead at Shield PlaneMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision); // Now we create a spring arm component. This will be to attach a camera to for Third Person View SpringArm = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("SpringArm0")); SpringArm->AttachTo(PlaneMesh); // Attach it to the plane mesh, so we follow its orientaion, not the root's //SpringArm->AttachTo(RootComponent); // ** DEBUG ** //SpringArm->TargetArmLength = 460.0f; // The camera follows at this distance behind the character SpringArm->TargetArmLength = 1000.0f; // The camera follows at this distance behind the character SpringArm->SocketOffset = FVector(0.f, 0.f, 160.f); SpringArm->bEnableCameraLag = false; SpringArm->CameraLagSpeed = 1.0f; SpringArm->bDoCollisionTest = false; // Now create Third Person camera component TP_Camera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("CameraTP0")); TP_Camera->AttachTo(SpringArm, USpringArmComponent::SocketName); // Attach to spring arm //TP_Camera->bUseControllerViewRotation = false; // Don't rotate camera with controller TP_Camera->bUsePawnControlRotation = false; // Don't rotate camera with controller //TP_Camera->PostProcessSettings.AutoExposureMaxBrightness = 0.1; TP_Camera->PostProcessSettings.bOverride_AutoExposureMinBrightness = true; TP_Camera->PostProcessSettings.AutoExposureMinBrightness = 0.05; TP_Camera->PostProcessSettings.bOverride_AutoExposureMaxBrightness = true; TP_Camera->PostProcessSettings.AutoExposureMaxBrightness = 0.05; // Now create First Person camera component FP_Camera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("CameraFP0")); FP_Camera->AttachTo(PlaneMesh); // Attach to Craft Mesh //FP_Camera->bUseControllerViewRotation = false; // Don't rotate camera with controller FP_Camera->bUsePawnControlRotation = false; // Don't rotate camera with controller FP_Camera->PostProcessSettings.bOverride_AutoExposureMinBrightness = true; FP_Camera->PostProcessSettings.AutoExposureMinBrightness = 0.05; FP_Camera->PostProcessSettings.bOverride_AutoExposureMaxBrightness = true; FP_Camera->PostProcessSettings.AutoExposureMaxBrightness = 0.05; // Now Add the spotlight CraftSpotLight = PCIP.CreateDefaultSubobject<USpotLightComponent>(this, TEXT("CraftSpotLight0")); CraftSpotLight->Activate(); CraftSpotLight->SetVisibility(true); CraftSpotLight->Intensity = 30000.f; CraftSpotLight->SetMobility(EComponentMobility::Movable); CraftSpotLight->AttachTo(PlaneMesh); CraftSpotLight->SetRelativeLocation(FVector(100.f, 0.f, 0.f)); CraftSpotLight->AttenuationRadius = 5000.f; CraftSpotLight->SetCastShadows(true); // Enable Third Person Camera by default. bIsThirdPerson = true; FP_Camera->Deactivate(); TP_Camera->Activate(); // Set handling parameters Acceleration = 1000.f; TurnSpeed = 100.f; MaxSpeed = 4000.f; MinSpeed = -4000.f; CurrentXAxisSpeed = 0.f; CurrentZAxisSpeed = 0.f; CurrentYAxisSpeed = 0.f; Deceleration = 50.f; ReturnSpeed = 0.f; AxisSmoothing = 5.f; // Set Up Weapon Handling weapon = 0; lastfired = 0; primary_on = false; weap_cycle = 1; // -- Set up line trace to allow us to work out where the 2D crosshair is pointing in 3Dspace. CrossHair_TraceParams = FCollisionQueryParams(FName(TEXT("CrossHair__Trace")), true, this); CrossHair_TraceParams.bTraceComplex = true; CrossHair_TraceParams.bTraceAsyncScene = true; CrossHair_TraceParams.bReturnPhysicalMaterial = false; CrossHair_Hit = FHitResult(ForceInit); //Set Up Inventories //PlayerInv = ReconOneInventory(); // Set Up Helpers //WeapInfo = ReconOneWeaponInfo(); // Behaviour //ShieldLevel = MAX_SHIELD; }