Exemplo n.º 1
0
void DrawDebugDirectionalArrow(const UWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, float ArrowSize, FColor const& Color, bool bPersistentLines, float LifeTime, uint8 DepthPriority)
{
	// no debug line drawing on dedicated server
	if (GEngine->GetNetMode(InWorld) != NM_DedicatedServer)
	{
		if (ArrowSize <= 0)
		{
			ArrowSize = 10.f;
		}

		DrawDebugLine(InWorld, LineStart, LineEnd, Color, bPersistentLines, LifeTime);

		FVector Dir = (LineEnd-LineStart);
		Dir.Normalize();
		FVector Up(0, 0, 1);
		FVector Right = Dir ^ Up;
		if (!Right.IsNormalized())
		{
			Dir.FindBestAxisVectors(Up, Right);
		}
		FVector Origin = FVector::ZeroVector;
		FMatrix TM;
		// get matrix with dir/right/up
		TM.SetAxes(&Dir, &Right, &Up, &Origin);

		// since dir is x direction, my arrow will be pointing +y, -x and -y, -x
		float ArrowSqrt = FMath::Sqrt(ArrowSize);
		FVector ArrowPos;
		DrawDebugLine(InWorld, LineEnd, LineEnd + TM.TransformPosition(FVector(-ArrowSqrt, ArrowSqrt, 0)), Color, bPersistentLines, LifeTime, DepthPriority);
		DrawDebugLine(InWorld, LineEnd, LineEnd + TM.TransformPosition(FVector(-ArrowSqrt, -ArrowSqrt, 0)), Color, bPersistentLines, LifeTime, DepthPriority);
	}
}
Exemplo n.º 2
0
/**
 * Render a debug circle on the screen (Y axis is normal to the circle)
 *
 * @param inLocation		World space location of the circle
 * @param inRotation		Rotation of the circle (Y axis is normal to the circle)
 * @param inRadius			The radius of the circle
 * @param withColor			The color of the circle
 * @param inSegments		Number of segments to divide the circle into
 * @param bShaded			Whether to shade the inside of the circle
 */
void RenderManager::DrawDebugCircle(const Vec4f& inLocation, const Quaternion& inRotation, const float inRadius, const ColorVector& withColor, const int inSegments, const bool bShaded) 
{
	const Matrix4x4 rotMatrix = inRotation.GetRotationMatrix();
	const Vec4f xAxis = rotMatrix.GetXAxis();
	const Vec4f zAxis = rotMatrix.GetZAxis();
	const float theta = 2*PI/inSegments;

	// Generate the circle vertices
	Vec4f* circleVerts = new Vec4f[inSegments];

	float currTheta = 0.f;
	for(int i=0; i<inSegments; i++, currTheta+=theta)
	{
		circleVerts[i] = inLocation + inRadius*cos(currTheta)*xAxis + inRadius*sin(currTheta)*zAxis;
	}

	for(int i=0; i<inSegments; i++)
	{
		DrawDebugLine(circleVerts[i], circleVerts[(i+1)%inSegments], withColor);
	}

	if(bShaded)
	{
		for(int i=0; i<inSegments; i++)
		{
			DrawDebugLine(inLocation, circleVerts[i], ColorVector::Black);
		}
	}

	delete[] circleVerts;
}
Exemplo n.º 3
0
void UMWBotWeaponComponent::Fire()
{
	if (!CanFire())
	{
		return;
	}

	// cast a line
	FHitResult hit;
	FCollisionQueryParams traceParams;
	traceParams.AddIgnoredActor(GetOwner());

	const int32 randSeed = FMath::Rand();
	FRandomStream randStream(randSeed);
	
	const FVector traceStart = GetComponentLocation();
	const FVector aimDir = GetComponentRotation().Vector();
	const FVector shotDir = randStream.VRandCone(aimDir, FMath::DegreesToRadians(Spread));
	const FVector traceEnd = traceStart + shotDir * 1e5;

	GetWorld()->LineTraceSingle(hit, traceStart, traceEnd, ECollisionChannel::ECC_Visibility, traceParams);

	ProcessHit(hit);

	// temporary draw
	
	if (hit.bBlockingHit)
	{
		DrawDebugLine(GetWorld(), traceStart, hit.ImpactPoint, FColor::Red, false, -1.f, 0, 10);
	}
	else
	{
		DrawDebugLine(GetWorld(), traceStart, traceEnd, FColor::Red, false, -1.f, 0, 10);
	}
}
Exemplo n.º 4
0
bool UVREditorMode::IsHandAimingTowardsCapsule( UViewportInteractor* Interactor, const FTransform& CapsuleTransform, FVector CapsuleStart, const FVector CapsuleEnd, const float CapsuleRadius, const float MinDistanceToCapsule, const FVector CapsuleFrontDirection, const float MinDotForAimingAtCapsule ) const
{
	bool bIsAimingTowards = false;
	const float WorldScaleFactor = GetWorldScaleFactor();

	FVector LaserPointerStart, LaserPointerEnd;
	if( Interactor->GetLaserPointer( /* Out */ LaserPointerStart, /* Out */ LaserPointerEnd ) )
	{
		const FVector LaserPointerStartInCapsuleSpace = CapsuleTransform.InverseTransformPosition( LaserPointerStart );
		const FVector LaserPointerEndInCapsuleSpace = CapsuleTransform.InverseTransformPosition( LaserPointerEnd );

		FVector ClosestPointOnLaserPointer, ClosestPointOnUICapsule;
		FMath::SegmentDistToSegment(
			LaserPointerStartInCapsuleSpace, LaserPointerEndInCapsuleSpace,
			CapsuleStart, CapsuleEnd,
			/* Out */ ClosestPointOnLaserPointer,
			/* Out */ ClosestPointOnUICapsule );

		const bool bIsClosestPointInsideCapsule = ( ClosestPointOnLaserPointer - ClosestPointOnUICapsule ).Size() <= CapsuleRadius;

		const FVector TowardLaserPointerVector = ( ClosestPointOnLaserPointer - ClosestPointOnUICapsule ).GetSafeNormal();

		// Apply capsule radius
		ClosestPointOnUICapsule += TowardLaserPointerVector * CapsuleRadius;

		if( false )	// @todo vreditor debug
		{
			const float RenderCapsuleLength = ( CapsuleEnd - CapsuleStart ).Size() + CapsuleRadius * 2.0f;
			// @todo vreditor:  This capsule draws with the wrong orientation
			if( false )
			{
				DrawDebugCapsule( GetWorld(), CapsuleTransform.TransformPosition( CapsuleStart + ( CapsuleEnd - CapsuleStart ) * 0.5f ), RenderCapsuleLength * 0.5f, CapsuleRadius, CapsuleTransform.GetRotation() * FRotator( 90.0f, 0, 0 ).Quaternion(), FColor::Green, false, 0.0f );
			}
			DrawDebugLine( GetWorld(), CapsuleTransform.TransformPosition( ClosestPointOnLaserPointer ), CapsuleTransform.TransformPosition( ClosestPointOnUICapsule ), FColor::Green, false, 0.0f );
			DrawDebugSphere( GetWorld(), CapsuleTransform.TransformPosition( ClosestPointOnLaserPointer ), 1.5f * WorldScaleFactor, 32, FColor::Red, false, 0.0f );
			DrawDebugSphere( GetWorld(), CapsuleTransform.TransformPosition( ClosestPointOnUICapsule ), 1.5f * WorldScaleFactor, 32, FColor::Green, false, 0.0f );
		}

		// If we're really close to the capsule
		if( bIsClosestPointInsideCapsule ||
			( ClosestPointOnUICapsule - ClosestPointOnLaserPointer ).Size() <= MinDistanceToCapsule )
		{
			const FVector LaserPointerDirectionInCapsuleSpace = ( LaserPointerEndInCapsuleSpace - LaserPointerStartInCapsuleSpace ).GetSafeNormal();

			if( false )	// @todo vreditor debug
			{
				DrawDebugLine( GetWorld(), CapsuleTransform.TransformPosition( FVector::ZeroVector ), CapsuleTransform.TransformPosition( CapsuleFrontDirection * 5.0f ), FColor::Yellow, false, 0.0f );
				DrawDebugLine( GetWorld(), CapsuleTransform.TransformPosition( FVector::ZeroVector ), CapsuleTransform.TransformPosition( -LaserPointerDirectionInCapsuleSpace * 5.0f ), FColor::Purple, false, 0.0f );
			}

			const float Dot = FVector::DotProduct( CapsuleFrontDirection, -LaserPointerDirectionInCapsuleSpace );
			if( Dot >= MinDotForAimingAtCapsule )
			{
				bIsAimingTowards = true;
			}
		}
	}

	return bIsAimingTowards;
}
Exemplo n.º 5
0
void UAIPerceptionComponent::DrawDebugInfo(UCanvas* Canvas)
{
    if (Canvas == nullptr)
    {
        return;
    }

    UWorld* World = GetWorld();
    if (World)
    {
        UAIPerceptionSystem* PerceptionSys = UAIPerceptionSystem::GetCurrent(World);
        check(PerceptionSys);
        UFont* Font = GEngine->GetSmallFont();

        for (TActorPerceptionContainer::TIterator It(PerceptualData); It; ++It)
        {
            if (It->Key == NULL)
            {
                continue;
            }

            const FActorPerceptionInfo& ActorPerceptionInfo = It->Value;

            if (ActorPerceptionInfo.Target.IsValid())
            {
                const FVector TargetLocation = ActorPerceptionInfo.Target->GetActorLocation();
                float VerticalLabelOffset = 0.f;

                for (const auto& Stimulus : ActorPerceptionInfo.LastSensedStimuli)
                {
                    if (Stimulus.Strength >= 0)
                    {
                        const FVector ScreenLoc = Canvas->Project(Stimulus.StimulusLocation + FVector(0, 0, 30));
                        Canvas->DrawText(Font, FString::Printf(TEXT("%s: %.2f a:%.2f")
                                                               , *PerceptionSys->GetSenseName(Stimulus.Type)
                                                               , Stimulus.Strength, Stimulus.GetAge())
                                         , ScreenLoc.X, ScreenLoc.Y + VerticalLabelOffset);

                        VerticalLabelOffset += 17.f;

                        const FColor DebugColor = PerceptionSys->GetSenseDebugColor(Stimulus.Type);
                        DrawDebugSphere(World, Stimulus.StimulusLocation, 30.f, 16, DebugColor);
                        DrawDebugLine(World, Stimulus.ReceiverLocation, Stimulus.StimulusLocation, DebugColor);
                        DrawDebugLine(World, TargetLocation, Stimulus.StimulusLocation, FColor::Black);
                    }
                }
            }
        }

        for (auto Sense : SensesConfig)
        {
            Sense->DrawDebugInfo(*Canvas, *this);
        }
    }
}
Exemplo n.º 6
0
/**
 * Render debug coordinated axes on the screen (Color code: x - red, y - green, z - blue)
 *
 * @param inLocation		World space location of the axes
 * @param inRotation		Rotation of the axes
 * @param inSize			The length, width and height of the axes
 */
void RenderManager::DrawDebugAxes(const Vec4f& inLocation, const Quaternion& inRotation, const Vec3f& inSize) 
{
	const Matrix4x4 rotMatrix = inRotation.GetRotationMatrix();
	const Vec4f xAxis = rotMatrix.GetXAxis();
	const Vec4f yAxis = rotMatrix.GetYAxis();
	const Vec4f zAxis = rotMatrix.GetZAxis();

	// Render the axes
	DrawDebugLine(inLocation, inLocation + inSize.x*xAxis, ColorVector::Red); 
	DrawDebugLine(inLocation, inLocation + inSize.y*yAxis, ColorVector::Green); 
	DrawDebugLine(inLocation, inLocation + inSize.z*zAxis, ColorVector::Blue); 
}
Exemplo n.º 7
0
// Called when the game starts or when spawned
void AFireTrail::BeginPlay()
{
	Super::BeginPlay();

	const FVector RayStart = GetActorLocation();
	const FVector Direction = GetActorRotation().Vector();
	FVector RayEnd = RayStart + (Direction * 150.0f);

	FCollisionQueryParams RayParameters(TEXT("TraceWallCollision"), true, this);
	RayParameters.bTraceAsyncScene = true;
	RayParameters.bReturnPhysicalMaterial = false;
	RayParameters.bTraceComplex = true;

	FHitResult Hit(ForceInit);
	bool bHitSomething = GetWorld()->LineTraceSingleByChannel(Hit, RayStart, RayEnd, ECC_WorldStatic, RayParameters);

	if (!bHitSomething) {
		UE_LOG(LogTemp, Warning, TEXT("F*****G RAY HIT NOTHING!"));
	}
	else {
		AActor* HitObject = Hit.GetActor();
		if (!HitObject)
			UE_LOG(LogTemp, Warning, TEXT("F*****G RAY HIT NO ACTOR!"));

		UPrimitiveComponent* HitComp = Hit.GetComponent();
		if (!HitComp)
			UE_LOG(LogTemp, Warning, TEXT("F*****G RAY HIT NO COMPONENT!"));

		//if (HitObject && HitObject->ActorHasTag(FName("IndestructibleBlock"))) {
		if (HitObject) {
			RayEnd = HitObject->GetActorLocation() - FVector(100.0f, 0.0f, 0.0f);
			UE_LOG(LogTemp, Warning, TEXT("HIT! RayEnd : %f, %f, %f"), RayEnd.X, RayEnd.Y, RayEnd.Z);
			DrawDebugLine(GetWorld(), RayStart, RayEnd, FColor::Red, false, 10.0f);
		}
	}
	DrawDebugLine(GetWorld(), RayStart, RayEnd, FColor::Green, false, 10.0f);

	const FVector Extents = FVector((RayEnd - RayStart).Size() / 2, 30.0f, 30.0f);
	//UE_LOG(LogTemp, Warning, TEXT("Box Extents : %f, %f, %f"), Extents.X, Extents.Y, Extents.Z);

	FVector BoxLocation = RayStart + (Direction * 75.0f);
	BoxLocation.Z = 60.0f;
	OverlapComp->SetWorldLocation(BoxLocation, false, nullptr, ETeleportType::TeleportPhysics);
	OverlapComp->SetBoxExtent(Extents);

	//DrawDebugSolidBox(GetWorld(), RayStart, Extents, FColor::Blue, false, 10.0f);

	PSystem->Activate(true);
}
void UPathFindingComponent::DrawPath(FVector start, TArray<FVector>& route, FColor color, float duration, float thickness)
{
	if (duration <= 0.0f)
	{
		DrawDebugLine(GetWorld(), start, route.Last(), color, true, -1.0f, (uint8)'\000', thickness);
		for (auto index = 0; index < route.Num() - 1; index++)
			DrawDebugLine(GetWorld(), route[index], route[index + 1], color, true, -1.0f, (uint8)'\000', thickness);
	}
	else
	{
		DrawDebugLine(GetWorld(), start, route.Last(), color, false, duration, (uint8)'\000', thickness);
		for (auto index = 0; index < route.Num() - 1; index++)
			DrawDebugLine(GetWorld(), route[index], route[index + 1], color, false, duration, (uint8)'\000', thickness);
	}
}
Exemplo n.º 9
0
void UCheatManager::TestCollisionDistance()
{
	APlayerController* PC = GetOuterAPlayerController();
	if(PC)
	{
		// Get view location to act as start point
		FVector ViewLoc;
		FRotator ViewRot;
		PC->GetPlayerViewPoint(ViewLoc, ViewRot);

		FlushPersistentDebugLines( GetOuterAPlayerController()->GetWorld() );//change the GetWorld

		// calculate from viewloc
		for (FObjectIterator Iter(AVolume::StaticClass()); Iter; ++Iter)
		{
			AVolume * Volume = Cast<AVolume>(*Iter);

			if (Volume->GetClass()->GetDefaultObject() != Volume)
			{
				FVector ClosestPoint(0,0,0);
				float Distance = Volume->GetBrushComponent()->GetDistanceToCollision(ViewLoc, ClosestPoint);
				float NormalizedDistance = FMath::Clamp<float>(Distance, 0.f, 1000.f)/1000.f;
				FColor DrawColor(255*NormalizedDistance, 255*(1-NormalizedDistance), 0);
				DrawDebugLine(GetWorld(), ViewLoc, ClosestPoint, DrawColor, true);

				UE_LOG(LogCheatManager, Log, TEXT("Distance to (%s) is %0.2f"), *Volume->GetName(), Distance);
			}
		}
	}
}
void AGameplayDebuggingHUDComponent::DrawPath(APlayerController* MyPC, class UGameplayDebuggingComponent *DebugComponent)
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
	static const FColor Grey(100,100,100);
	static const FColor PathColor(192,192,192);

	const int32 NumPathVerts = DebugComponent->PathPoints.Num();
	UWorld* DrawWorld = GetWorld();

	for (int32 VertIdx=0; VertIdx < NumPathVerts-1; ++VertIdx)
	{
		FVector const VertLoc = DebugComponent->PathPoints[VertIdx] + NavigationDebugDrawing::PathOffset;
		DrawDebugSolidBox(DrawWorld, VertLoc, NavigationDebugDrawing::PathNodeBoxExtent, VertIdx < int32(DebugComponent->NextPathPointIndex) ? Grey : PathColor, false);

		// draw line to next loc
		FVector const NextVertLoc = DebugComponent->PathPoints[VertIdx+1] + NavigationDebugDrawing::PathOffset;
		DrawDebugLine(DrawWorld, VertLoc, NextVertLoc, VertIdx < int32(DebugComponent->NextPathPointIndex) ? Grey : PathColor, false
			, -1.f, 0
			, NavigationDebugDrawing::PathLineThickness);
	}

	// draw last vert
	if (NumPathVerts > 0)
	{
		DrawDebugBox(DrawWorld, DebugComponent->PathPoints[NumPathVerts-1] + NavigationDebugDrawing::PathOffset, FVector(15.f), Grey, false);
	}

#endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
}
AUsableActor* AXtremeJanitorCharacter::GetUsableInView()
{
	FVector CamLoc;
	FRotator CamRot;

	if (Controller == NULL)
		return NULL;

	Controller->GetPlayerViewPoint(CamLoc, CamRot);
	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxUseDistance);

	FCollisionQueryParams TraceParams(FName(TEXT("TraceUsableActor")), true, this);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = true;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	// Cette ligne sera en commentaire plus tard
	DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	return Cast<AUsableActor>(Hit.GetActor());
}
Exemplo n.º 12
0
/// <summary> Draws one of the paths using one list from each list of lists </summary>
/// <param name="n"> The position, in each list of lists, of the list with the values for this path </param>
void UMovementTracker::DrawNthPath(size_t n)
{
	//Checks if there is no mistake in the different lists
	if (VectorList[n].Num() == TimeList[n].Num() && TimeList[n].Num() == NameList[n].Num())
	{
		//previous tells us if the previous point was drawn. It allows us to know if a line needs to be drawn between the points
		//but also tells us when the path's beginning was. It allows us to start at that point next update to save on resources.
		bool previous = false;
		for (size_t i = PathStartArray[n]; i < VectorList[n].Num(); i++)
		{
			if ((TimeLength <= 0 || TimeList[n][i] >= ElapsedTime - TimeLength) && TimeList[n][i] <= ElapsedTime && NameList[n][i] == GetOwner()->GetName())
			{
				DrawDebugPoint(World, VectorList[n][i], 20.0f, FColor(255, 0, 0));
				if (previous) //Draw the line between the previous point and this one
					DrawDebugLine(World, VectorList[n][i - 1], VectorList[n][i], FColor(0, 0, 255), false, -1.0f, (uint8)'\000', 5.0f);
				else //Sets the start of next update's sweep
					PathStartArray[n] = i;
				previous = true;
			}
			else
			{
				previous = false;
				if (previous) //We are at the end of the path that we want to draw, no need to continue checking the rest of the path
					break;
			}
		}
	}
}
Exemplo n.º 13
0
void UCrowdManager::DrawDebugPathOptimization(const dtCrowdAgent* CrowdAgent) const
{
	FVector Pt0 = Recast2UnrealPoint(DetourAgentDebug->optStart) + CrowdDebugDrawing::Offset * 1.25f;
	FVector Pt1 = Recast2UnrealPoint(DetourAgentDebug->optEnd) + CrowdDebugDrawing::Offset * 1.25f;

	DrawDebugLine(GetWorld(), Pt0, Pt1, CrowdDebugDrawing::PathOpt, false, -1.0f, SDPG_World, 2.5f);
}
Exemplo n.º 14
0
void UAStarAgentComponent::DrawDebugInformation()
{
  if (m_path->path.Num() == 0)
    return;

  for (int i = 0; i < m_path->path.Num() - 1; i++)
  {
    FVector pos1 = m_path->path[i];
    FVector pos2 = m_path->path[i + 1];

    DrawDebugPoint(
      GetWorld(),
      FVector(pos1.X, pos1.Y, pos1.Z),
      7,
      FColor(255, 255, 0)
      );

    DrawDebugLine(GetWorld(),
      FVector(pos1.X, pos1.Y, pos1.Z), FVector(pos2.X, pos2.Y, pos2.Z),
      FColor(255, 255, 0), false, -1, 0, 5.f
      );
  }

  DrawDebugPoint(
    GetWorld(),
    FVector(m_path->path.Last().X, m_path->path.Last().Y, m_path->path.Last().Z),
    7,
    FColor(255, 255, 0)
    );
}
Exemplo n.º 15
0
//========================================================================
void APlatformActor::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	if (m_Target)
	{
		auto z = FVector(0, 0, 30);
		DrawDebugLine(GetWorld(), GetActorLocation() + z, m_Target->GetActorLocation() + z, FColor::Yellow, false, -1.f, 0, 1.3f);

		auto d = 40.0f;

		auto mypos = GetActorLocation();

		bool hasCompanion = std::any_of(Cont(gHexEditor->m_AllCompanions), [&](auto& c) { return FVector::Dist(mypos, c->GetActorLocation()) < d; });
		if (hasCompanion)
		{
			m_Target->Off();
			return;
		}

		auto dist = FVector::Dist(gHexGame->Dude->GetActorLocation(), GetActorLocation());
		if (dist < d)
		{
			m_Target->Off();
		}
	}
}
Exemplo n.º 16
0
void APawnWithCamera::DoTrace()
{
	FVector Loc = CameraOne->GetActorLocation();
	UE_LOG(LogClass, Error, TEXT("Loc is %s"), *Loc.ToString());
	FRotator Rot = CameraOne->GetActorRotation();
	UE_LOG(LogClass, Error, TEXT("Rot is %s"), *Rot.ToString());
	FVector Start = Loc;
	UE_LOG(LogClass, Error, TEXT("Start is %s"), *Start.ToString());
	FVector End = Loc + (Rot.Vector() * Distance);
	UE_LOG(LogClass, Error, TEXT("End is %s"), *End.ToString());
	TempActor->SetActorLocation(End);

	FCollisionQueryParams TraceParam = FCollisionQueryParams(FName(TEXT("Trace")), true, this);
	TraceParam.bTraceComplex = true;
	TraceParam.bTraceAsyncScene = true;
	TraceParam.bReturnPhysicalMaterial = false;
	TraceParam.AddIgnoredActor(this);

	FHitResult Hit(ForceInit);

	GetWorld()->LineTraceSingle(Hit, Start, End, ECC_Pawn, TraceParam);
	DrawDebugLine(GetWorld(), Start, End, FColor(255, 0, 0), false, -1, 0, 12.33f);

	if (Hit.bBlockingHit)
	{
		UE_LOG(LogClass, Error, TEXT("Hit Something"));
	}
	else
	{
		UE_LOG(LogClass, Error, TEXT("No Hit"));
	}
}
Exemplo n.º 17
0
void DrawDebugData(UWorld* World, const FTransform& TransformVector, const FVector& StartLoc, const FVector& TargetLoc, FColor Color)
{
	FVector Start = TransformVector.TransformPosition(StartLoc);
	FVector End = TransformVector.TransformPosition(TargetLoc);

	DrawDebugLine(World, Start, End, Color);
}
Exemplo n.º 18
0
void UCarditWeapon::Fire()
{
	auto Camera = Cast<ACarditCharacter>(GetOwner())->GetCamera();
	auto CameraLocation = Camera->GetComponentLocation();
	auto EndLocation = Camera->GetComponentLocation() + (Camera->GetComponentRotation().Vector() * MaxRangeInCm);

	DrawDebugLine(GetWorld(), CameraLocation, EndLocation, FColor(255, 0, 0), false, 5.f, 0, 2.5f);

	FHitResult OutHit;

	if (GetWorld()->LineTraceSingleByChannel(
		OutHit,
		CameraLocation,
		EndLocation,
		ECC_Visibility
	)
		)
	{
		if (Cast<ACarditCharacter>(OutHit.GetActor()))
		{
			GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Character hit");
			Cast<ACarditGameMode>(UGameplayStatics::GetGameMode(GetWorld()))->DealDamageOntoCharacter(Cast<ACarditCharacter>(OutHit.GetActor()), DamagePerShot);
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("Non-character hit"));
		}
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Nothing hit"));
	}
}
Exemplo n.º 19
0
void FNavMeshPath::DebugDraw(const ANavigationData* NavData, FColor PathColor, UCanvas* Canvas, bool bPersistent, const uint32 NextPathPointIndex) const
{
	Super::DebugDraw(NavData, PathColor, Canvas, bPersistent, NextPathPointIndex);

#if WITH_RECAST
	const ARecastNavMesh* RecastNavMesh = Cast<const ARecastNavMesh>(NavData);		
	const TArray<FNavigationPortalEdge>& Edges = (const_cast<FNavMeshPath*>(this))->GetPathCorridorEdges();	
	const int32 CorridorEdgesCount = Edges.Num();

	for (int32 EdgeIndex = 0; EdgeIndex < CorridorEdgesCount; ++EdgeIndex)
	{
		DrawDebugLine(NavData->GetWorld(), Edges[EdgeIndex].Left + NavigationDebugDrawing::PathOffset, Edges[EdgeIndex].Right + NavigationDebugDrawing::PathOffset
			, FColor::Blue, bPersistent, /*LifeTime*/-1.f, /*DepthPriority*/0
			, /*Thickness*/NavigationDebugDrawing::PathLineThickness);
	}

	if (Canvas && RecastNavMesh && RecastNavMesh->bDrawLabelsOnPathNodes)
	{
		UFont* RenderFont = GEngine->GetSmallFont();
		for (int32 VertIdx = 0; VertIdx < PathPoints.Num(); ++VertIdx)
		{
			// draw box at vert
			FVector const VertLoc = PathPoints[VertIdx].Location 
				+ FVector(0, 0, NavigationDebugDrawing::PathNodeBoxExtent.Z*2)
				+ NavigationDebugDrawing::PathOffset;
			const FVector ScreenLocation = Canvas->Project(VertLoc);

			FNavMeshNodeFlags NodeFlags(PathPoints[VertIdx].Flags);
			const UClass* NavAreaClass = RecastNavMesh->GetAreaClass(NodeFlags.Area);

			Canvas->DrawText(RenderFont, FString::Printf(TEXT("%d: %s"), VertIdx, *GetNameSafe(NavAreaClass)), ScreenLocation.X, ScreenLocation.Y );
		}
	}
#endif // WITH_RECAST
}
Exemplo n.º 20
0
void AWeapon::FireProjectile()
{
	FHitResult ObjectHit(EForceInit::ForceInit);
	FVector CameraLocation;
	FRotator CameraRotation;
	WeaponOwner->Controller->GetPlayerViewPoint(CameraLocation, CameraRotation);
	const FVector TraceStart = CameraLocation;
	const FVector TraceDirection = CameraRotation.Vector();

	FRandomStream WeaponRandomStream(FMath::Rand());
	const float SpreadCone = FMath::DegreesToRadians(Config.Spread * 0.5);
	const FVector ShotDirection = WeaponRandomStream.VRandCone(TraceDirection, SpreadCone, SpreadCone);
	const FVector TraceEnd = TraceStart + ShotDirection * Config.Range;

	FCollisionQueryParams TraceParams(FName(TEXT("TraceShot")), true, this);
	TraceParams.AddIgnoredActor(WeaponOwner);

	//Weapon Recoil Calculation
	WeaponOwner->AddControllerPitchInput(-(Config.Recoil));
	if (FMath::FRand() >= 0.65f)
	{
		WeaponOwner->AddControllerYawInput(Config.Recoil);
	}
	else
	{
		WeaponOwner->AddControllerYawInput(-(Config.Recoil));
	}

	const UWorld* World = GetWorld();

	//debug code start//////////////////////////////////

	if (GEngine)
	{
		//GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, ShotDirection.ToString());
	}

	DrawDebugLine(
		World,
		TraceStart,
		TraceEnd,
		FColor(255, 0, 0),
		false, 3, 0,
		3.0
		);

	//debug code end////////////////////////////////////

	bool HitDetected = false;
	if (World)
	{
		HitDetected = World->LineTraceSingle(ObjectHit, TraceStart, TraceEnd, ECollisionChannel::ECC_WorldDynamic, TraceParams);
		if (HitDetected)
		{
			DoDamage(ObjectHit);
		}
	}
}
Exemplo n.º 21
0
void UAISenseConfig_Sight::DrawDebugInfo(UCanvas& Canvas, UAIPerceptionComponent& PerceptionComponent) const
{
    /*PeripheralVisionAngleDegrees*/
    const AActor* BodyActor = PerceptionComponent.GetBodyActor();
    if (BodyActor != nullptr)
    {
        UWorld* World = BodyActor->GetWorld();
        FVector BodyLocation, BodyFacing;
        PerceptionComponent.GetLocationAndDirection(BodyLocation, BodyFacing);
        DrawDebugCylinder(World, BodyLocation, BodyLocation + FVector(0, 0, -50), SightRadius, 32, UAISense_Sight::GetDebugSightRangeColor());
        DrawDebugCylinder(World, BodyLocation, BodyLocation + FVector(0, 0, -50), LoseSightRadius, 32, UAISense_Sight::GetDebugLoseSightColor());

        const float SightPieLength = FMath::Max(LoseSightRadius, SightRadius);
        DrawDebugLine(World, BodyLocation, BodyLocation + (BodyFacing * SightPieLength), UAISense_Sight::GetDebugSightRangeColor());
        DrawDebugLine(World, BodyLocation, BodyLocation + (BodyFacing.RotateAngleAxis(PeripheralVisionAngleDegrees, FVector::UpVector) * SightPieLength), UAISense_Sight::GetDebugSightRangeColor());
        DrawDebugLine(World, BodyLocation, BodyLocation + (BodyFacing.RotateAngleAxis(-PeripheralVisionAngleDegrees, FVector::UpVector) * SightPieLength), UAISense_Sight::GetDebugSightRangeColor());
    }
}
Exemplo n.º 22
0
void UCrowdManager::DrawDebugCorners(const dtCrowdAgent* CrowdAgent) const
{
	{
		FVector P0 = Recast2UnrealPoint(CrowdAgent->npos);
		for (int32 Idx = 0; Idx < CrowdAgent->ncorners; Idx++)
		{
			FVector P1 = Recast2UnrealPoint(&CrowdAgent->cornerVerts[Idx * 3]);
			DrawDebugLine(GetWorld(), P0 + CrowdDebugDrawing::Offset, P1 + CrowdDebugDrawing::Offset, CrowdDebugDrawing::Corner, false, -1.0f, SDPG_World, 2.0f);
			P0 = P1;
		}
	}

	if (CrowdAgent->ncorners > 0 && (CrowdAgent->cornerFlags[CrowdAgent->ncorners - 1] & DT_STRAIGHTPATH_OFFMESH_CONNECTION))
	{
		FVector P0 = Recast2UnrealPoint(&CrowdAgent->cornerVerts[(CrowdAgent->ncorners - 1) * 3]);
		DrawDebugLine(GetWorld(), P0, P0 + CrowdDebugDrawing::Offset * 2.0f, CrowdDebugDrawing::CornerLink, false, -1.0f, SDPG_World, 2.0f);
	}
}
Exemplo n.º 23
0
void AFlockFish::Debug()
{
	if (DebugMode)
	{
		FVector actorLocation = this->GetActorLocation();
		FVector forwardVector = (this->GetActorForwardVector() * AvoidanceDistance) + actorLocation;
		FVector forwardVector2 = (this->GetActorForwardVector() * (AvoidanceDistance * 0.1)) + actorLocation;

		DrawDebugLine(
			GetWorld(),
			actorLocation,
			forwardVector,
			FColor::Magenta,
			false, -1, 0,
			10
			);

		FColor indicatorColor = FColor::Cyan;
		if (nearbyEnemies.IsValidIndex(0))
		{
			indicatorColor = FColor::Red;
		}
		else if (nearbyPrey.IsValidIndex(0) && isFull == false)
		{
			indicatorColor = FColor::Green;
		}
		DrawDebugSphere(
			GetWorld(),
			actorLocation,
			FishInteractionSphere->GetScaledSphereRadius(),
			20,
			indicatorColor
			);
		DrawDebugLine(
			GetWorld(),
			actorLocation,
			forwardVector2,
			indicatorColor,
			true, 10, 0,
			20
			);
	}

}
Exemplo n.º 24
0
/* Draw segment of the spline between two given nodes */
void ASplineComponent::DrawCurveSegment(FVector p0, FVector p1, FVector p2, FVector p3)
{
	float distance = FVector::Dist(p0, p3);
	int32 roundedDistance = (int32)distance;

	FVector start = this->CalculatePoint(0, p0, p1, p2, p3);

	// Draw tangents
	DrawDebugLine(this->GetWorld(), p0, p0 + (p1 - p0) / 2, FColor::Red, false, -1, 0, 8);
	DrawDebugLine(this->GetWorld(), p3, p3 + (p2 - p3) / 2, FColor::Green, false, -1, 0, 8);

	// Draw spline segment
	for (int i = 1; i < roundedDistance; ++i)
	{
		FVector end = CalculatePoint((float)i / distance, p0, p1, p2, p3);
		DrawDebugLine(this->GetWorld(), start, end, FColor::Yellow, false, -1, 0, 10);
		start = end;
	}
}
Exemplo n.º 25
0
static void DrawCircle(const UWorld* InWorld, const FVector& Base, const FVector& X, const FVector& Y, const FColor& Color, float Radius, int32 NumSides, bool bPersistentLines, float LifeTime, uint8 DepthPriority = 0)
{
	const float	AngleDelta = 2.0f * PI / NumSides;
	FVector	LastVertex = Base + X * Radius;

	for(int32 SideIndex = 0;SideIndex < NumSides;SideIndex++)
	{
		const FVector Vertex = Base + (X * FMath::Cos(AngleDelta * (SideIndex + 1)) + Y * FMath::Sin(AngleDelta * (SideIndex + 1))) * Radius;
		DrawDebugLine(InWorld, LastVertex, Vertex, Color, bPersistentLines, LifeTime, DepthPriority);
		LastVertex = Vertex;
	}
}
Exemplo n.º 26
0
void APawnWithCamera::LMB_Out()
{
	APlayerController* MyController = GetWorld()->GetFirstPlayerController();
	AMyHUD *Hudref = Cast<AMyHUD>(MyController->GetHUD());
	FVector WorldMousePos = Hudref->GetMOuseWorldPosition();

	FVector Start = GetActorLocation();

	DistanceWithToPoints = FVector::Dist(Start, WorldMousePos);

	//DrawDebugSphere(GetWorld(), WorldMousePos, 16.f, 8, FColor(83, 155, 83, 255), false, 0.15f);
	DrawDebugLine(GetWorld(), Start, WorldMousePos, FColor(255, 0, 0), true, 0.5f, 0, 5.0f);
}
Exemplo n.º 27
0
void AWeapon::ProcessInstantHit(const FHitResult &Impact, const FVector &Origin, const FVector &ShootDir, int32 RandomSeed, float ReticleSpread)
{
	const FVector EndTrace = Origin + ShootDir * WeaponConfig.WeaponRange;
	const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : EndTrace;
	DrawDebugLine(this->GetWorld(), Origin, Impact.TraceEnd, FColor::Black, true, 10000, 10.f);

	AEnemy *Enemy = Cast<AEnemy>(Impact.GetActor());
	if (Enemy)
	{
		GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Red, "YOU HIT AN ENEMY!!");
		Enemy->Destroy();
	}
}
Exemplo n.º 28
0
void ALeafNode::DebugDraw()
{
	const FVector location = GetActorLocation();

	if (UWorld* const a_World = Tree->tidGetWorld())
	{

		FColor Color = FColor::Red;

		//Left
		FVector Start = FVector(location.X, location.Y, location.Z);
		FVector End = FVector(location.X, location.Y + Dimensions.Y, location.Z);

		DrawDebugLine(a_World, Start, End, Color);

		//Bottom
		Start = FVector(location.X, location.Y, location.Z);
		End = FVector(location.X + Dimensions.X, location.Y, location.Z);

		DrawDebugLine(a_World, Start, End, Color);

		//Right
		Start = FVector(location.X + Dimensions.X, location.Y, location.Z);
		End = FVector(location.X + Dimensions.X, location.Y + Dimensions.Y, location.Z);

		DrawDebugLine(a_World, Start, End, Color);

		//Top
		Start = FVector(location.X + Dimensions.X, location.Y + Dimensions.Y, location.Z);
		End = FVector(location.X, location.Y + Dimensions.Y, location.Z);

		DrawDebugLine(a_World, Start, End, Color);

		// Draw debug box at center of node
		//const FVector2D roomPosition = FVector2D(location.X + Dimensions.X * 0.5f, location.Y + Dimensions.Y * 0.5f);
		//DrawDebugBox(a_World, FVector(roomPosition.X, roomPosition.Y, 5.0f), FVector(10.0f), FColor::Blue);

	}
}
void AGameplayDebuggingHUDComponent::DrawPerception(APlayerController* PC, class UGameplayDebuggingComponent *DebugComponent)
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
	if (!DebugComponent)
	{
		return;
	}

	PrintString(DefaultContext, FColor::Green, TEXT("\nPERCEPTION COMPONENT\n"));
	PrintString(DefaultContext, FString::Printf(TEXT("Draw Colors:")));
	PrintString(DefaultContext, *DebugComponent->PerceptionLegend);

	PrintString(DefaultContext, FString::Printf(TEXT("\nDistance Sensor-PlayerPawn: %.1f\n"), DebugComponent->DistanceFromSensor));
	PrintString(DefaultContext, FString::Printf(TEXT("Distance Pawn-PlayerPawn: %.1f\n"), DebugComponent->DistanceFromPlayer));

	float VerticalLabelOffset = 0.f;
	for (const FGameplayDebuggerShapeElement& Shape : DebugComponent->PerceptionShapeElements)
	{
		switch (Shape.GetType())
		{
		case EGameplayDebuggerShapeElement::String:
		{
			const FVector& Loc = Shape.Points[0];
			const FVector ScreenLoc = DefaultContext.Canvas->Project(Loc);

			PrintString(DefaultContext, Shape.GetFColor(), Shape.Description, ScreenLoc.X, ScreenLoc.Y + VerticalLabelOffset);
			VerticalLabelOffset += 17;
		}
			break;
		case EGameplayDebuggerShapeElement::Segment:
		{
			DrawDebugLine(World, Shape.Points[0], Shape.Points[1], Shape.GetFColor());
		}
			break;
		case EGameplayDebuggerShapeElement::SinglePoint:
		{
			DrawDebugSphere(World, Shape.Points[0], Shape.ThicknesOrRadius, 16, Shape.GetFColor());
		}
			break;
		case EGameplayDebuggerShapeElement::Cylinder:
		{
			static const float DefaultCylinderHeight = 50.f;
			const FVector EndLocation = ensure(Shape.Points.Num() > 1) ? Shape.Points[1] : (Shape.Points[0] + FVector::UpVector * DefaultCylinderHeight);
			DrawDebugCylinder(World, Shape.Points[0], Shape.Points[1], Shape.ThicknesOrRadius, 16, Shape.GetFColor());
		}
			break;
		}
	}

#endif // !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
}
void FGameplayDebuggerCategory_AI::DrawPath(UWorld* World)
{
	static const FColor InactiveColor(100, 100, 100);
	static const FColor PathColor(192, 192, 192);
	static const FColor PathGoalColor(255, 255, 255);

	const int32 NumPathVerts = PathDataPack.PathPoints.Num();
	for (int32 Idx = 0; Idx < NumPathVerts; Idx++)
	{
		const FVector PathPoint = PathDataPack.PathPoints[Idx] + NavigationDebugDrawing::PathOffset;
		DrawDebugSolidBox(World, PathPoint, NavigationDebugDrawing::PathNodeBoxExtent, Idx < DataPack.NextPathPointIndex ? InactiveColor : PathColor);
	}

	for (int32 Idx = 1; Idx < NumPathVerts; Idx++)
	{
		const FVector P0 = PathDataPack.PathPoints[Idx - 1] + NavigationDebugDrawing::PathOffset;
		const FVector P1 = PathDataPack.PathPoints[Idx] + NavigationDebugDrawing::PathOffset;

		DrawDebugLine(World, P0, P1, Idx < DataPack.NextPathPointIndex ? InactiveColor : PathColor, false, -1.0f, 0, NavigationDebugDrawing::PathLineThickness);
	}

	if (NumPathVerts && DataPack.bPathHasGoalActor)
	{
		const FVector P0 = PathDataPack.PathPoints.Last() + NavigationDebugDrawing::PathOffset;
		const FVector P1 = DataPack.PathGoalLocation + NavigationDebugDrawing::PathOffset;

		DrawDebugLine(World, P0, P1, PathGoalColor, false, -1.0f, 0, NavigationDebugDrawing::PathLineThickness);
	}
}