The Tank Turret is not rotation

Hey Joshi,

Couple things to get you moving.

Firstly, when submitting code with your problem it will be much much easier for people to read it if you paste the text itself into a code block instead of pasting screenshots of the code. Check out this link

Second, I would recommend renaming your ProjectileRef variable in Tank.h with a more accurate description. Perhaps PlayerControllerRef or TankPlayerController etc… I assume this is a copy and paste error but reading the code is made that much more difficult when variables don’t describe their purpose. If you do change the name remember that if you don’t use the editor’s auto renaming functionality you’ll need to change the rest of the places where you use that variable to match the new name. If you’re not sure you’ve gotten them all. You can try to compile and the compiler should get mad at you if you’ve missed any :slight_smile:

Finally, onto the problem. I see you’ve tried to add some debug logging into these functions;

ABasePawn::RotateTurret

ATank::Tick

This is a great idea for trying to backtrack through the logic and figure out where the “hole” is in the logic. Unfortunately since both of your prints are printing the same thing it makes it harder to reason about what exactly is and is not working.

I’d recommend changing the prints and perhaps adding some more. Here’s a rough idea of what you could add. NOTE This is just partial code and I haven’t check/compiled it so there could be typos or errors. (It’s much harder to copy/paste/modify your example code when it is in screenshot form :wink: )

ATank::Tick(float DeltaTime)
{
        UE_LOG(LogTemp, Warning, TEXT("Updaing our tank in general"));
        if(ProjectileRef)
        {
            UE_LOG(LogTemp, Warning, TEXT("We have a legitimate controller reference"));
            ProjectileRef->GetHitResult... blah blah blah (CHANGE PROJECTILEREF NAME :) )
            UE_LOG(LogTemp, Warning, TEXT("Mouse Cursor Hit Result Location is %s"), *HitResult.ImpactPoint.ToString());
            RotateTurret(HitResult.ImpactPoint)
        }
}

then in BasePawn

ABasePawn::RotateTurret(FVector Locate)
{
        UE_LOG(LogTemp, Warning, TEXT("Trying to rotate the turret towards %s"), *Locate.ToString());
    ... rest of the code

If you try these and let us know what sort of prints you’re getting then it will give us some more insight into the problem.

If you’re not seeing your tank tick at all then we’re not creating it or have disabled updates. Something like that.

If your ticking, but not seeing anything else, then we’ve probably failed to get the player controller.

If you’re ticking, getting a hit point and it’s some crazy numbers something else is happening.

etc…

Hopefully you’re still around and find some of this useful, or maybe you’ve already solved it for yourself by now. Let me know.

All the best!

1 Like