示例#1
0
void UAreaOfEffect::Use()
{
	Super::Use();
	static FName NAME_TestMove = FName(TEXT("TestMove"));
	FCollisionQueryParams SphereParams(NAME_TestMove, false, GetOwner());
	FCollisionObjectQueryParams QueryParams = FCollisionObjectQueryParams(FCollisionObjectQueryParams::InitType::AllDynamicObjects);
	TArray<FOverlapResult> Overlaps;

	GetWorld()->OverlapMultiByObjectType(Overlaps, GetOwner()->GetActorLocation(), FQuat::Identity, QueryParams, FCollisionShape::MakeSphere(500.f), SphereParams);

	for (int32 i = 0; i < Overlaps.Num(); ++i)
	{
		//

		FOverlapResult const& Overlap = Overlaps[i];
		ABETCharacter* Mine = Cast<ABETCharacter>(Overlap.GetActor());

		//	AEffectOverTime* appliedDebuff;
		if (Mine != nullptr)
		{
			//appliedDebuff = debuff;
//			if (debuff){
			UsedFunction(Mine);
			//Mine->Destroy();
			//					appliedDebuff->SetActive();
//					appliedDebuff->AttachRootComponentToActor(Mine);		
//					DrawDebugSphere(GetWorld(), GetOwner()->GetActorLocation(), 24, 32, FColor(255, 0, 0), false, -1.f);
//			}
			//This is where you will attach an effect over time...			
		}
	}
	Overlaps.Empty();
	DeactivateAbility();
}
const FHitResult UGrabber::GetFirstPhysicsObjectFromTrace()
{
	FHitResult HitResult;
	FCollisionQueryParams queryParams(FName(""), false, GetOwner());
	GetWorld()->LineTraceSingleByObjectType(
		OUT HitResult, PawnLocation, GetLineTraceEnd(), FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody), queryParams
	);

	return HitResult;
}
示例#3
0
const FHitResult UGrabber::GetFirstPhysicsBodyInReach()
{
	/// Raycast to reach distance
	FHitResult HitResult;
	GetWorld()->LineTraceSingleByObjectType(
		OUT HitResult, GetReachLineStart(), GetReachLineEnd(),
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		FCollisionQueryParams(FName(TEXT("")), false, GetOwner())
	);
	return HitResult;
}
示例#4
0
const FHitResult UGrabber::GetFirstPhysicsBodyInReach()
{
	///Line-Trace (AKA ray-cast) 
	FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());
	FHitResult HitResult;
	GetWorld()->LineTraceSingleByObjectType(
		OUT HitResult,
		GetReachLineStart(),
		GetReachLineEnd(),
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		TraceParameters
	);
	return HitResult;
}
static bool RayTrace(const AActor &Actor, const FVector &Start, const FVector &End) {
  FHitResult OutHit;
  static FName TraceTag = FName(TEXT("VehicleTrace"));
  FCollisionQueryParams CollisionParams(TraceTag, true);
  CollisionParams.AddIgnoredActor(&Actor);

  const bool Success = Actor.GetWorld()->LineTraceSingleByObjectType(
        OutHit,
        Start,
        End,
        FCollisionObjectQueryParams(FCollisionObjectQueryParams::AllDynamicObjects),
        CollisionParams);

  return Success && OutHit.bBlockingHit;
}
示例#6
0
/// Return hit for first physics body in reach
const FHitResult UGrabber::GetFirstPhysicsBodyInReach(){
	FVector PlayerViewPointLocation;
	/// Set up query parameters
	FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());

	/// Line-trace (AKA ray-cast) out to reach distance
	FHitResult HitResult;
	GetWorld()->LineTraceSingleByObjectType(
		OUT HitResult,
		GetReachLineStart(),
		GetReachLineEnd(),
		FCollisionObjectQueryParams(ECC_PhysicsBody),
		TraceParameters
	);
	return HitResult;
}
void ANavigationObjectBase::FindBase()
{
	if ( GetWorld()->HasBegunPlay() )
	{
		return;
	}

	if( ShouldBeBased() )
	{
		// not using find base, because don't want to fail if LD has navigationpoint slightly interpenetrating floor
		FHitResult Hit(1.f);
		
		const float Radius = CapsuleComponent->GetScaledCapsuleRadius();
		FVector const CollisionSlice(Radius, Radius, 1.f);
		
		// check for placement
		const FVector TraceStart = GetActorLocation();
		const FVector TraceEnd = GetActorLocation() - FVector(0.f,0.f, 4.f * CapsuleComponent->GetScaledCapsuleHalfHeight());

		static FName NAME_NavFindBase = FName(TEXT("NavFindBase"));

		GetWorld()->SweepSingleByObjectType( Hit, TraceStart, TraceEnd, FQuat::Identity, FCollisionObjectQueryParams(ECC_WorldStatic), FCollisionShape::MakeBox(CollisionSlice), FCollisionQueryParams(NAME_NavFindBase, false));

		// @fixme, ensure object is on the navmesh?
// 		if( Hit.Actor != NULL )
// 		{
// 			if (Hit.Normal.Z > Scout->WalkableFloorZ)
// 			{
// 				const FVector HitLocation = TraceStart + (TraceEnd - TraceStart) * Hit.Time;
// 				TeleportTo(HitLocation + FVector(0.f,0.f,CapsuleComponent->GetScaledCapsuleHalfHeight()-2.f), GetActorRotation(), false, true);
// 			}
// 			else
// 			{
// 				Hit.Actor = NULL;
// 			}
// 		}

		if (GoodSprite)
		{
			GoodSprite->SetVisibility(true);
		}
		if (BadSprite)
		{
			BadSprite->SetVisibility(false);
		}
	}
}
示例#8
0
vector<AGameObject*> APlayerControl::ShapePick( FVector pos, FCollisionShape shape,
  SetAGameObject AcceptedTypes, SetAGameObject NotTypes )
{
  // We use the base shapepick, then filter
  FCollisionQueryParams fcqp;
  TArray<FOverlapResult> overlaps;
  FQuat quat( 0.f, 0.f, 0.f, 0.f );
  FCollisionObjectQueryParams objectTypes = FCollisionObjectQueryParams( 
    FCollisionObjectQueryParams::InitType::AllObjects );
  // To query using a specific object TYPE, use OverlapMultiByProfile()
  GetWorld()->OverlapMultiByObjectType( overlaps, pos, quat, objectTypes, shape, fcqp );
  
  // indicate where the search shape is.
  //DrawDebugCylinder( GetWorld(), pos, pos + FVector( 0, 0, shape.Capsule.HalfHeight*2.f ), shape.Capsule.HitBoundsCylindricalRadius,
  //  16, FColor::Yellow, 1, 10.f, 0 );
  //info( FS( "Shape overlaps %d units", overlaps.Num() ) );

  map< float, vector<AGameObject*> > objects;
  for( int i = 0; i < overlaps.Num(); i++ )
  {
    if( AGameObject* go = Cast<AGameObject>( overlaps[i].GetActor() ) )
    {
      if( go->Dead ) skip;

      if( AcceptedTypes.size()   &&   !go->IsAny( AcceptedTypes ) )  skip;

      if( go->IsAny( NotTypes ) )  skip;
      
      // Duplicates DO happen
      if( !in( objects, go ) )
      {
        float d = FVector::Dist( pos, go->Pos ); // order 
        objects[ d ].push_back( go );
        //info( FS( "  * %s", *go->GetName() ) );
        //DrawDebugCylinder( GetWorld(), go->Pos, go->Pos + FVector(0,0,go->Height()),
        //  go->HitBoundsCylindricalRadius(), 16, FColor::Green, 1, 10.f, 0 );
      }
    }
  }

  vector<AGameObject*> os;
  for( pair< const float, vector<AGameObject*> > p : objects )
    for( AGameObject* go : p.second )
      os += go;
  return os;
}
示例#9
0
FHitResult UGrabber::FindTheFirstReachingObject() {
	// Get the viewport
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(ViewPortLocation, ViewPortRotation);
	//UE_LOG(LogTemp, Warning, TEXT("Location: %s, Rotation: %s"), *ViewPortLocation.ToString(), *ViewPortRotation.ToString());

	// Calculate of the endpoint of debug line
	EndPointOfLine = ViewPortLocation + ViewPortRotation.Vector() * LineReach;

	// Draw the debug line
	DrawDebugLine(
		GetWorld(),
		ViewPortLocation,
		EndPointOfLine,
		FColor(255.0f, 0.0f, 0.0f),
		false,
		0.0f,
		0.0f,
		10.0f
	);

	// The variable store the hit result info
	FHitResult HitResInfo;

	// Some settings of the line tracing
	FCollisionQueryParams CollisionParams(FName(TEXT("")), false, GetOwner());

	// Do the line tracing
	GetWorld()->LineTraceSingleByObjectType(
		HitResInfo,
		ViewPortLocation,
		EndPointOfLine,
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		CollisionParams
	);

	// Log the result of the line tracing
	AActor* HitActor = HitResInfo.GetActor();
	if (HitActor) {
		UE_LOG(LogTemp, Warning, TEXT("The hitting object's name is: %s"), *(HitActor->GetName()));
	}

	return HitResInfo;
}
FActorPositionTraceResult FActorPositioning::TraceWorldForPosition(const UWorld& InWorld, const FSceneView& InSceneView, const FVector& RayStart, const FVector& RayEnd, const TArray<AActor*>* IgnoreActors)
{
	TArray<FHitResult> Hits;

	FCollisionQueryParams Param(TEXT("DragDropTrace"), true);
	Param.bTraceAsyncScene = true;
	
	if (IgnoreActors)
	{
		Param.AddIgnoredActors(*IgnoreActors);
	}

	FActorPositionTraceResult Results;
	if ( InWorld.LineTraceMultiByObjectType(Hits, RayStart, RayEnd, FCollisionObjectQueryParams(FCollisionObjectQueryParams::InitType::AllObjects), Param) )
	{
		{
			// Filter out anything that should be ignored
			FSuspendRenderingThread SuspendRendering(false);
			Hits.RemoveAll([&](const FHitResult& Hit){
				return IsHitIgnored(Hit, InSceneView);
			});
		}

		// Go through all hits and find closest
		float ClosestHitDistanceSqr = TNumericLimits<float>::Max();

		for (const auto& Hit : Hits)
		{
			const float DistanceToHitSqr = (Hit.ImpactPoint - RayStart).SizeSquared();
			if (DistanceToHitSqr < ClosestHitDistanceSqr)
			{
				ClosestHitDistanceSqr = DistanceToHitSqr;
				Results.Location = Hit.Location;
				Results.SurfaceNormal = Hit.Normal.GetSafeNormal();
				Results.State = FActorPositionTraceResult::HitSuccess;
				Results.HitActor = Hit.Actor;
			}
		}
	}

	return Results;
}
示例#11
0
vector<AGameObject*> APlayerControl::ComponentPickExcept( AGameObject* object, UPrimitiveComponent* up, vector<AGameObject*> except,
  FString queryObjectType, vector<FString> intersectableTypes )
{
  FComponentQueryParams fqp;
  except += object;

  // this will cause the object to pick itself if you don't put it in the except group
  for( AGameObject* o : except )
    if( o )  fqp.AddIgnoredActor( o );

  FCollisionObjectQueryParams objectTypes = FCollisionObjectQueryParams( 
    FCollisionObjectQueryParams::InitType::AllObjects );

  for( FString channelName : intersectableTypes )
  {
    ECollisionChannel channel = CollisionChannels[channelName];
    objectTypes.AddObjectTypesToQuery( channel ); // Channel 3 is the RESOURCES channel.
  }

  TArray<FOverlapResult> overlaps;
  FRotator ro = up->GetComponentRotation();
  FVector ve = up->GetComponentLocation();

  // QUERY on channel 
  ECollisionChannel queryChannel = CollisionChannels[queryObjectType];
  GetWorld()->ComponentOverlapMultiByChannel( overlaps, up, ve, ro, queryChannel, fqp, objectTypes );
  
  map<float, AGameObject*> objects;
  for( int i = 0; i < overlaps.Num(); i++ )
  {
    if( AGameObject* go = Cast<AGameObject>( overlaps[i].GetActor() ) )
    {
      float d = FVector::Dist( object->Pos, go->Pos );
      objects[ d ] = go;
    }
  }

  return MakeVectorS( objects );
}
示例#12
0
const FHitResult UGrabber::GetFirstPhysicsBodyInReach()
{
	/// Setup query parameters
	FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());
	FHitResult HitResult;
	/// Line-trace (Aka Ray-cast) out to reach distance
	GetWorld()->LineTraceSingleByObjectType(
		OUT HitResult,
		GetReachLineStart(),
		GetReachLineEnd(),
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		TraceParameters
	);

	/// See what we hit
	AActor* ActorHit = HitResult.GetActor();
	if (ActorHit) {
		UE_LOG(LogTemp, Warning, TEXT("Line trace hit: %s"), *(ActorHit->GetName()))
	}

	return HitResult;
}
示例#13
0
const FHitResult UGrabber::GetFirstPhysicsBodyInReach()
{
	FHitResult LineTraceHit;

	///Setup query parameters
	FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());

	GetWorld()->LineTraceSingleByObjectType(
		OUT LineTraceHit,
		GetReachLineStart(),
		GetReachLineEnd(),
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		TraceParameters
	);

	AActor* actorHit = LineTraceHit.GetActor();
	if (actorHit) {
		UE_LOG(LogTemp, Warning, TEXT("Line trace hit: %s"), *(actorHit->GetName()));
	}
	
	return LineTraceHit;
}
//
// AICTPGameGameMode::TryRadialDamage
//
void AICTPGameGameMode::TryRadialDamage( AActor* Damager, float DamageAmount, float DamageRadius, FVector Origin, TSubclassOf<UDamageType> DamageTypeClass ) const
{
	auto World = GetWorld();
	check( World );

	// Make sure we ignore actors on our team.
	TArray<AActor*>		   IgnoreActors;
	TArray<FOverlapResult> Overlaps;
	FCollisionQueryParams  Params;
	World->OverlapMultiByObjectType( Overlaps, Origin, FQuat::Identity, FCollisionObjectQueryParams( FCollisionObjectQueryParams::AllDynamicObjects ), FCollisionShape::MakeSphere( DamageRadius ), Params );
	for( int i = 0; i < Overlaps.Num(); ++i )
	{
		auto Actor = Overlaps[i].Actor.Get();
		if( !CanDamage( Damager, Actor ) )
		{
			IgnoreActors.Add( Actor );
		}
	}

	// Apply radial damage on non-ignored actors.
	UGameplayStatics::ApplyRadialDamage( World, DamageAmount, Origin, DamageRadius, DamageTypeClass, IgnoreActors, Damager, 
		Damager == nullptr ? nullptr : Damager->GetInstigatorController() ); 
}
示例#15
0
float UAISense_Sight::Update()
{
	static const FName NAME_AILineOfSight = FName(TEXT("AILineOfSight"));

	SCOPE_CYCLE_COUNTER(STAT_AI_Sense_Sight);

	const UWorld* World = GEngine->GetWorldFromContextObject(GetPerceptionSystem()->GetOuter());

	if (World == NULL)
	{
		return SuspendNextUpdate;
	}

	int32 TracesCount = 0;
	static const int32 InitialInvalidItemsSize = 16;
	TArray<int32> InvalidQueries;
	TArray<FAISightTarget::FTargetId> InvalidTargets;
	InvalidQueries.Reserve(InitialInvalidItemsSize);
	InvalidTargets.Reserve(InitialInvalidItemsSize);

	AIPerception::FListenerMap& ListenersMap = *GetListeners();

	FAISightQuery* SightQuery = SightQueryQueue.GetData();
	for (int32 QueryIndex = 0; QueryIndex < SightQueryQueue.Num(); ++QueryIndex, ++SightQuery)
	{
		if (TracesCount < MaxTracesPerTick)
		{
			FPerceptionListener& Listener = ListenersMap[SightQuery->ObserverId];
			ensure(Listener.Listener.IsValid());
			FAISightTarget& Target = ObservedTargets[SightQuery->TargetId];
					
			const bool bTargetValid = Target.Target.IsValid();
			const bool bListenerValid = Listener.Listener.IsValid();

			// @todo figure out what should we do if not valid
			if (bTargetValid && bListenerValid)
			{
				AActor* TargetActor = Target.Target.Get();
				const FVector TargetLocation = TargetActor->GetActorLocation();
				const FDigestedSightProperties& PropDigest = DigestedProperties[SightQuery->ObserverId];
				const float SightRadiusSq = SightQuery->bLastResult ? PropDigest.LoseSightRadiusSq : PropDigest.SightRadiusSq;

				if (CheckIsTargetInSightPie(Listener, PropDigest, TargetLocation, SightRadiusSq))
				{
//					UE_VLOG_SEGMENT(Listener.Listener.Get()->GetOwner(), Listener.CachedLocation, TargetLocation, FColor::Green, TEXT("%s"), *(Target.TargetId.ToString()));

					FVector OutSeenLocation(0.f);
					// do line checks
					if (Target.SightTargetInterface != NULL)
					{
						int32 NumberOfLoSChecksPerformed = 0;
						if (Target.SightTargetInterface->CanBeSeenFrom(Listener.CachedLocation, OutSeenLocation, NumberOfLoSChecksPerformed, Listener.Listener->GetBodyActor()) == true)
						{
							Listener.RegisterStimulus(TargetActor, FAIStimulus(*this, 1.f, OutSeenLocation, Listener.CachedLocation));
							SightQuery->bLastResult = true;
						}
						else
						{
//							UE_VLOG_LOCATION(Listener.Listener.Get()->GetOwner(), TargetLocation, 25.f, FColor::Red, TEXT(""));
							Listener.RegisterStimulus(TargetActor, FAIStimulus(*this, 0.f, TargetLocation, Listener.CachedLocation, FAIStimulus::SensingFailed));
							SightQuery->bLastResult = false;
						}

						TracesCount += NumberOfLoSChecksPerformed;
					}
					else
					{
						// we need to do tests ourselves
						/*const bool bHit = World->LineTraceTest(Listener.CachedLocation, TargetLocation
							, FCollisionQueryParams(NAME_AILineOfSight, true, Listener.Listener->GetBodyActor())
							, FCollisionObjectQueryParams(ECC_WorldStatic));*/
						FHitResult HitResult;
						const bool bHit = World->LineTraceSingle(HitResult, Listener.CachedLocation, TargetLocation
							, FCollisionQueryParams(NAME_AILineOfSight, true, Listener.Listener->GetBodyActor())
							, FCollisionObjectQueryParams(ECC_WorldStatic));

						++TracesCount;

						if (bHit == false || (HitResult.Actor.IsValid() && HitResult.Actor->IsOwnedBy(TargetActor)))
						{
							Listener.RegisterStimulus(TargetActor, FAIStimulus(*this, 1.f, TargetLocation, Listener.CachedLocation));
							SightQuery->bLastResult = true;
						}
						else
						{
//							UE_VLOG_LOCATION(Listener.Listener.Get()->GetOwner(), TargetLocation, 25.f, FColor::Red, TEXT(""));
							Listener.RegisterStimulus(TargetActor, FAIStimulus(*this, 0.f, TargetLocation, Listener.CachedLocation, FAIStimulus::SensingFailed));
							SightQuery->bLastResult = false;
						}
					}
				}
				else
				{
//					UE_VLOG_SEGMENT(Listener.Listener.Get()->GetOwner(), Listener.CachedLocation, TargetLocation, FColor::Red, TEXT("%s"), *(Target.TargetId.ToString()));
					Listener.RegisterStimulus(TargetActor, FAIStimulus(*this, 0.f, TargetLocation, Listener.CachedLocation, FAIStimulus::SensingFailed));
					SightQuery->bLastResult = false;
				}

				SightQuery->Importance = CalcQueryImportance(Listener, TargetLocation, SightRadiusSq);

				// restart query
				SightQuery->Age = 0.f;
			}
			else
			{
				// put this index to "to be removed" array
				InvalidQueries.Add(QueryIndex);
				if (bTargetValid == false)
				{
					InvalidTargets.AddUnique(SightQuery->TargetId);
				}
			}
		}
		else
		{
			// age unprocessed queries so that they can advance in the queue during next sort
			SightQuery->Age += 1.f;
		}

		SightQuery->RecalcScore();
	}

	if (InvalidQueries.Num() > 0)
	{
		for (int32 Index = InvalidQueries.Num() - 1; Index >= 0; --Index)
		{
			// removing with swapping here, since queue is going to be sorted anyway
			SightQueryQueue.RemoveAtSwap(InvalidQueries[Index], 1, /*bAllowShrinking*/false);
		}

		if (InvalidTargets.Num() > 0)
		{
			for (const auto& TargetId : InvalidTargets)
			{
				// remove affected queries
				RemoveAllQueriesToTarget(TargetId, DontSort);
				// remove target itself
				ObservedTargets.Remove(TargetId);
			}

			// remove holes
			ObservedTargets.Compact();
		}
	}

	// sort Sight Queries
	SortQueries();

	//return SightQueryQueue.Num() > 0 ? 1.f/6 : FLT_MAX;
	return 0.f;
}
示例#16
0
const FHitResult UGrabber::GetFirstPysicsBodyInReach()
{
	// Ray-cast to reach distance
	FHitResult LineTraceHitResult;
	FCollisionQueryParams CollisionQueryParams(FName(TEXT("")), false, GetOwner());

	GetWorld()->LineTraceSingleByObjectType(OUT LineTraceHitResult, GetReachLineStart(), GetReachLineEnd(), FCollisionObjectQueryParams(
		ECC_PhysicsBody), CollisionQueryParams);
	// See what we hit
	auto ActorHit = LineTraceHitResult.GetActor();

	if (ActorHit) {
		UE_LOG(LogTemp, Warning, TEXT("Hit %s"), *(ActorHit->GetName()));
	}

	return LineTraceHitResult;
}
void URadialForceComponent::UpdateCollisionObjectQueryParams()
{
	CollisionObjectQueryParams = FCollisionObjectQueryParams(ObjectTypesToAffect);
}
EPathFindingState UGettingEndNode::FindPath(UWorld* world, FPathFindingInformation& pathFindInfo, TArray<FVector>& resultRoute)
{
	if (pathFindInfo.WaypointList.Num() == 0)
		return EPathFindingState::None;
	if (index == 0)
	{
		pathFindInfo.EndNode = pathFindInfo.WaypointList[0];
		minDistance = (pathFindInfo.EndNode->GetComponentLocation() - pathFindInfo.EndLocation).Size();
		index++;
	}
	while (index < pathFindInfo.WaypointList.Num())
	{
		auto currentNode = pathFindInfo.WaypointList[index];
		auto currentDistance = (currentNode->GetComponentLocation() - pathFindInfo.EndLocation).Size();
		if (currentDistance < minDistance)
		{
			if (!world->LineTraceTestByObjectType(pathFindInfo.EndLocation, currentNode->GetComponentLocation(), FCollisionObjectQueryParams(ECollisionChannel::ECC_WorldStatic)))
			{
				pathFindInfo.EndNode = currentNode;
				minDistance = currentDistance;
			}
		}
		index++;
		if (pathFindInfo.Timer->GetElapsedTimeFromStart(0) >= pathFindInfo.MaxCaluclationTime)
			return EPathFindingState::GettingEndNode;
	}
	return EPathFindingState::LoadingFromDataMap;
}
示例#19
0
const FHitResult UGrabber::GetFirstPhysicsBodyInReach()
{
	/// Get Player position and view data
	FVector PlayerViewPointLocation;
	FRotator PlayerViewPointRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);

	/*UE_LOG(LogTemp, Warning, TEXT("Location: %s, Rotation: %s"), *PlayerViewPointLocation.ToString(), *PlayerViewPointRotation.ToString());*/

	/// Draw Debug Line based on how far can reach
	FVector LineTraceEnd = PlayerViewPointLocation + (PlayerViewPointRotation.Vector() * Reach);
	//DrawDebugLine(GetWorld(), PlayerViewPointLocation, LineTraceEnd, FColor(255, 0, 0), false, 0.f, 0.f, 10.f);

	/// Decide what can detect as collision
	FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());

	FHitResult LineTraceHit;
	GetWorld()->LineTraceSingleByObjectType(OUT LineTraceHit, PlayerViewPointLocation, LineTraceEnd, FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody), TraceParameters);

	AActor* ActorHit = LineTraceHit.GetActor();
	if (ActorHit) {
		UE_LOG(LogTemp, Warning, TEXT("Line Trace Hit: %s"), *(ActorHit->GetName()));
	}
	return LineTraceHit;
}
示例#20
0
FVector ASpawningVolume::returnRandomLocation()
{
	FVector PossibleSpawnPoint;
	UWorld* World = GetWorld();
	FHitResult HitResult;
	FCollisionQueryParams Params;
	Params.bFindInitialOverlaps = true;
	if (World){
		do{
			PossibleSpawnPoint = GetRandomPointInVolume();
			if (!World->LineTraceSingle(HitResult, PossibleSpawnPoint, FVector(PossibleSpawnPoint.X, PossibleSpawnPoint.Y, -100), Params, FCollisionObjectQueryParams())){
				break;
			}
			AActor* Actor = HitResult.Actor.Get();
			FString name = Actor->GetActorLabel();
		} while (!HitResult.Actor.Get()->GetActorLabel().StartsWith("Floor"));
	}
	return PossibleSpawnPoint;
}
void UParticleModuleCollision::PostLoad()
{
	Super::PostLoad();

	ObjectParams = FCollisionObjectQueryParams(CollisionTypes);
}
示例#22
0
/** This will set the StreamingLevels TMap with the current Streaming Level Status and also set which level the player is in **/
void GetLevelStreamingStatus( UWorld* World, TMap<FName,int32>& StreamingLevels, FString& LevelPlayerIsInName )
{
	FWorldContext &Context = GEngine->WorldContextFromWorld(World);

	// Iterate over the world info's level streaming objects to find and see whether levels are loaded, visible or neither.
	for( int32 LevelIndex=0; LevelIndex<World->StreamingLevels.Num(); LevelIndex++ )
	{
		ULevelStreaming* LevelStreaming = World->StreamingLevels[LevelIndex];

		if( LevelStreaming 
			&&  LevelStreaming->PackageName != NAME_None 
			&&	LevelStreaming->PackageName != World->GetOutermost()->GetFName() )
		{
			ULevel* Level = LevelStreaming->GetLoadedLevel();
			if( Level != NULL )
			{
				if( World->ContainsLevel( Level ) == true )
				{
					if( World->CurrentLevelPendingVisibility == Level )
					{
						StreamingLevels.Add( LevelStreaming->PackageName, LEVEL_MakingVisible );
					}
					else
					{
						StreamingLevels.Add( LevelStreaming->PackageName, LEVEL_Visible );
					}
				}
				else
				{
					StreamingLevels.Add( LevelStreaming->PackageName, LEVEL_Loaded );
				}
			}
			else
			{
				// See whether the level's world object is still around.
				UPackage* LevelPackage	= Cast<UPackage>(StaticFindObjectFast( UPackage::StaticClass(), NULL, LevelStreaming->PackageName ));
				UWorld*	  LevelWorld	= NULL;
				if( LevelPackage )
				{
					LevelWorld = UWorld::FindWorldInPackage(LevelPackage);
				}

				if( LevelWorld )
				{
					StreamingLevels.Add( LevelStreaming->PackageName, LEVEL_UnloadedButStillAround );
				}
				else if( GetAsyncLoadPercentage( *LevelStreaming->PackageName.ToString() ) >= 0 )
				{
					StreamingLevels.Add( LevelStreaming->PackageName, LEVEL_Loading );
				}
				else
				{
					StreamingLevels.Add( LevelStreaming->PackageName, LEVEL_Unloaded );
				}
			}
		}
	}

	
	// toss in the levels being loaded by PrepareMapChange
	for( int32 LevelIndex=0; LevelIndex < Context.LevelsToLoadForPendingMapChange.Num(); LevelIndex++ )
	{
		const FName LevelName = Context.LevelsToLoadForPendingMapChange[LevelIndex];
		StreamingLevels.Add(LevelName, LEVEL_Preloading);
	}


	ULevel* LevelPlayerIsIn = NULL;

	for( FConstPlayerControllerIterator Iterator = World->GetPlayerControllerIterator(); Iterator; ++Iterator )
	{
		APlayerController* PlayerController = *Iterator;

		if( PlayerController->GetPawn() != NULL )
		{
			// need to do a trace down here
			//TraceActor = Trace( out_HitLocation, out_HitNormal, TraceDest, TraceStart, false, TraceExtent, HitInfo, true );
			FHitResult Hit(1.f);

			// this will not work for flying around :-(
			static FName NAME_FindLevel = FName(TEXT("FindLevel"), true);			
			PlayerController->GetWorld()->LineTraceSingle(Hit,PlayerController->GetPawn()->GetActorLocation(), (PlayerController->GetPawn()->GetActorLocation()-FVector(0.f, 0.f, 256.f)), FCollisionQueryParams(NAME_FindLevel, true, PlayerController->GetPawn()), FCollisionObjectQueryParams(ECC_WorldStatic));

			/** @todo UE4 FIXME
			if( Hit.Level != NULL )
			{
				LevelPlayerIsIn = Hit.Level;
			}
			else 
			*/
			if( Hit.GetActor() != NULL )
			{
				LevelPlayerIsIn = Hit.GetActor()->GetLevel();
			}
			else if( Hit.Component != NULL && Hit.Component->GetOwner() != NULL )
			{
				AActor* Owner = Hit.Component->GetOwner();
				if (Owner)
				{
					LevelPlayerIsIn = Owner->GetLevel();
				}
				else
				{
					// This happens for BSP where the ModelComponent's outer is the level
					LevelPlayerIsIn = Hit.Component->GetTypedOuter<ULevel>();
				}
			}
		}
	}

	// this no longer seems to be getting the correct level name :-(
	LevelPlayerIsInName = LevelPlayerIsIn != NULL ? LevelPlayerIsIn->GetOutermost()->GetName() : TEXT("None");
}
示例#23
0
TArray<AActor*> URPGEffectBase::SpreadEffects(TArray<URPGEffectBase*> EffectsIn, FVector FromLoc, float Radius, int32 MaxTargets)
{
	TArray<AActor*> ActorHits;
	if ((!GetWorld()))
		return ActorHits;

	//TWeakObjectPtr<URPGEffectPeriodic> PeriodicEffect = Cast<URPGEffectPeriodic>(EffectIn);

	float TargetCounter = 0;
	//EffectSpec.SetEffect();

	FCollisionQueryParams SphereParams(this->GetFName(), false, CausedBy);
	//make sure we have world

	TArray<FOverlapResult> Overlaps;
	GetWorld()->OverlapMulti(Overlaps, FromLoc, FQuat::Identity, FCollisionShape::MakeSphere(Radius), SphereParams, FCollisionObjectQueryParams(FCollisionObjectQueryParams::InitType::AllDynamicObjects));


	for (FOverlapResult& overlap : Overlaps)
	{
		ActorHits.AddUnique(overlap.GetActor());
	}

	if (ActorHits.Num() > 0)
	{
		int32 TargetCounter = 0;
		if (MaxTargets > TargetCounter)
		{
			TargetCounter++;
			for (AActor* ActorHit : ActorHits)
			{
				URPGAttributeComponent* HitActorAttribute = ActorHit->FindComponentByClass<URPGAttributeComponent>();

				if (HitActorAttribute)
				{
					for (URPGEffectBase* effect : EffectsIn)
					{
						TWeakObjectPtr<URPGEffectPeriodic> periodicEffect = Cast<URPGEffectPeriodic>(effect);

						if (periodicEffect.IsValid())
						{
							periodicEffect->SetTarget(ActorHit);
							periodicEffect->SetCauser(CausedBy);
							periodicEffect->PreInitialize();
							periodicEffect->Initialize();

							HitActorAttribute->ApplyPeriodicEffect(periodicEffect.Get());
							continue;
						}


						effect->SetTarget(ActorHit);
						effect->SetCauser(CausedBy);
						effect->PreInitialize();
						effect->Initialize();
					}
				}
			}

		}
	}

	return ActorHits;
}
void UParticleModuleCollision::InitializeDefaults()
{
	if (!DampingFactor.IsCreated())
	{
		DampingFactor.Distribution = NewObject<UDistributionVectorUniform>(this, TEXT("DistributionDampingFactor"));
	}

	if (!DampingFactorRotation.IsCreated())
	{
		UDistributionVectorConstant* DistributionDampingFactorRotation = NewObject<UDistributionVectorConstant>(this, TEXT("DistributionDampingFactorRotation"));
		DistributionDampingFactorRotation->Constant = FVector(1.0f, 1.0f, 1.0f);
		DampingFactorRotation.Distribution = DistributionDampingFactorRotation; 
	}

	if (!MaxCollisions.IsCreated())
	{
		MaxCollisions.Distribution = NewObject<UDistributionFloatUniform>(this, TEXT("DistributionMaxCollisions"));
	}

	if (!ParticleMass.IsCreated())
	{
		UDistributionFloatConstant* DistributionParticleMass = NewObject<UDistributionFloatConstant>(this, TEXT("DistributionParticleMass"));
		DistributionParticleMass->Constant = 0.1f;
		ParticleMass.Distribution = DistributionParticleMass;
	}

	if (!DelayAmount.IsCreated())
	{
		UDistributionFloatConstant* DistributionDelayAmount = NewObject<UDistributionFloatConstant>(this, TEXT("DistributionDelayAmount"));
		DistributionDelayAmount->Constant = 0.0f;
		DelayAmount.Distribution = DistributionDelayAmount;
	}

	ObjectParams = FCollisionObjectQueryParams(CollisionTypes);
}