Tank Turret Jumps after Fire

Howdy Everyone,

I am following along in this course (which is difficult due to how quickly the instructor jumps through things), and have double-checked my code with the Git commits, and have everything the same. However, whenever I click the LMB while the game is running, I get the correct FIRE!!! in the console, but the tank turret jumps clockwise after almost every shot. I initially thought it might be an issue with this code:

void APawnBase::RotateTurret(FVector LookAtTarget)
{
FVector StartLocation = TurretMesh->GetComponentLocation();
FRotator TurretRotation = UKismetMathLibrary::FindLookAtRotation(StartLocation,
FVector(LookAtTarget.X, LookAtTarget.Y, TurretMesh->GetComponentLocation().Z));

TurretMesh->SetWorldRotation(TurretRotation);

}

Perhaps with the computation of the Z coord? Is this jumping expected behavior? Thanks!

Rich S.

You probably have the spawn point of the projectile to close to the barrel and they’re colliding.
Try adjusting that in the tank viewport and see what happens?

1 Like

Hi myhillion,

This was (is) occurring before the projectile was added to the project. I just completed the Spawing Actors lesson (which adds them) and moved the spawn point, but still have the tank turret jumping around. I figured out what it is actually doing, but not sure why it is doing it. Whatever location the turret is facing the first time you press fire, it always returns to that position after you press fire. So if the turret is pointing straight ahead the first time you press fire (12 o’clock), it will return there on each subsequent fire. Thanks!

Rich S.

It’s identical to my RotateTurret function and I don’t have this issue.
I’m wondering if the issue isn’t in the Fire function since the problem occurs after that initial fire.

DId you ever figure out what it was?

You still have the course on Udemy, right?

https://www.udemy.com/course/unrealcourse/learn/lecture/20648912#questions/11453898/

Luis seems to have solved it. Might be worth looking into @Rob_Brooks as it seems like it’s not a unique case?

Hi myrhillion,

I have not, but I had an idea that I intend to try, the next time I get a chance do some work on it. I am thinking the variable that holds the “start” position needs to be updated after every rotation, vices just after the first one. It is like it stores it the first time you click “Fire” but never updates again. Once I try this idea out, I’ll post back here.

Rich S.

Howdy DanM,

That sounds like my issue. I’ll give it a try, and I’ll post back. Thanks!

Rich S.

Howdy DanM,

Changing the ViewPort settings fixed the issue, but seems more like a hack, than an actual fix. The tank turret follows the mouse even when the viewport hasn’t captured the cursor. normally the cursor is captured when you click. When you change these settings, it only captures when you click. Not sure if this is desired behavior, a behavior caused by the game design, or a bug with the editor? It would seem that you wouldn’t want to be tracking the mouse, outside the play window? Regardless, thanks for the assist :slight_smile:
Rich S.

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

Privacy & Terms