DrawDebugSphere UE 5.0

I am slowly working through the Unreal 5.0 C++ Developer: Learn C++ and Make Video Games course.
I encountered an issue where I needed to make the debug sphere follow above my head. (12:20 into the video). The only way I could get it to work was to put the code in the BeginPlay() and also the Tick().

I tried

  • re-complying with the editor closed.
  • refresh Visual Studio Code Project.

Anyone else had this issue in 5.0?

Seems to work fine on my end. If you try removing it from BeginPlay and keeping it in Tick does it break again?

Got it worked out. I had PlayerControllerRef = Cast(GetController()); inside the Fire() iirc.

The problem is my mouse goes crazy and it’s not shooting where I’m pointing.

Where is your mouse hovering over during those times (this happens with Stephen’s as well btw)?

Unfortunately the function doesn’t provide a parameter that allows you to ignore actors. You’ll either need a custom trace channel and have the tank ignore it. Or copy and paste the definition of the function and add the tank to the ignored actors in the FCollisionQueryParams

Hmmm. I wasn’t up to the crosshair at the time of first seeing this issue. But now I have completed that part it is even more prevalent. I’m about to start the Winning and Losing tutorial. Does the problem get addressed later on? If not would your fix goin in the BasePawn.cpp where we are creating the RotateTurret function?

void ABasePawn::RotateTurret(FVector LookAtTarget)
{
	FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();
	FRotator LookAtRotation = FRotator(0.f, ToTarget.Rotation().Yaw, 0.f);
	TurrentMesh->SetWorldRotation(LookAtRotation);
}

It’s not RotateTurret. I gave you a hint as to the problem, the location you are providing to RotateTurret is the top of the tank.

This is basically what GetHitResultUnderCursor does which I more or less just copy pasted. The one difference I made was to ignore the tank via FCollisionQueryParams

if (TankPlayerController)
{
    FVector WorldLocation;
    FVector WorldDirection;
    if (TankPlayerController->DeprojectMousePositionToWorld(WorldLocation, WorldDirection))
    {
        FHitResult HitResult;
        // third argument is for an actor to ignore in the line trace
        FCollisionQueryParams Params(NAME_None, false, this); 
        if (GetWorld()->LineTraceSingleByChannel(HitResult, WorldLocation, WorldLocation + WorldDirection * 100000.0, ECC_Visibility, Params))
        {
            RotateTurret(HitResult.ImpactPoint);
        }
    }
}

Thanks DanM. The issue was that when I imported my different Mesh they were rotated 90 degrees. I went into the Static Mesh modified the Z axis then reimported. That corrected the issue. Thanks heaps!

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms