Tank Turning

Hello,

So I followed the lecture and built the turning mechanism for the tank with the added modification to make it keyboard only:

void UTankMovementComponent::MoveForward(float inputThrow)
{
	UE_LOG(LogTemp, Warning, TEXT("Forward throttle: %f"), inputThrow);

	leftTrack->SetThrottle(inputThrow);
	rightTrack->SetThrottle(inputThrow);
}

void UTankMovementComponent::MoveBackward(float inputThrow)
{
	UE_LOG(LogTemp, Warning, TEXT("Backward throttle: %f"), inputThrow);

	leftTrack->SetThrottle(-inputThrow);
	rightTrack->SetThrottle(-inputThrow);
}

void UTankMovementComponent::TurnLeft(float inputThrow)
{
	UE_LOG(LogTemp, Warning, TEXT("Left throttle: %f, %f"), -inputThrow, inputThrow);

	leftTrack->SetThrottle(-inputThrow);
	rightTrack->SetThrottle(inputThrow);
}

void UTankMovementComponent::TurnRight(float inputThrow)
{
	UE_LOG(LogTemp, Warning, TEXT("Right throttle: %f, %f"), inputThrow, -inputThrow);

	leftTrack->SetThrottle(inputThrow);
	rightTrack->SetThrottle(-inputThrow);
}

I have noticed that when I try to turn right or left the log acknowledges the intend to turn, but remains motionless, unless the tank is in the air, falling or floating when it does make a difference and it does turn.

Any help is greatly appreciated!

EDIT: It does go forwards and backwards as intended. I’m on version 4.15.2.

Have you done the lectures where Ben talks about friction? My guess is there’s too much friction when your tank is on the ground. That would explain why it works in the air, and not on the ground.

Yes, I forgot to mention it does go backwards and forwards as intended.

If you can turn in the air then it may still be an issue of friction. I think the default physics means that it is harder to turn left or right than to go straight forwards/backwards.

Can you increase you forwards force for us to a higher number? add another 0 on the end. If that doesnt work, add another 0. repeat a few more times and if that doesnt solve the problem then I’m stumped without downloading your project

2 Likes

That did it, but rather than adding another 0, I merely doubled it. I still need to be careful for my tank not to fly away now due to speed. Onwards to that then. Thank you for clarifying that turning left and right gives more friction.

1 Like

Super :slight_smile:

There is a bit of a balancing act regarding the speeds/friction :slight_smile:
Dont worry too much about sliding around etc. They’ll address it later

Yeah, I had a similar issue, what I did was rotate the pitch of the track’s force up by 0.01 degree and that worked a charm
in the header
float TrackForcePitch = 0.01;
and the cpp

        auto ForceApplied = GetForwardVector() * Throttle * TrackMaxDrivingForce; 
    	auto AlterAngle = FRotator(TrackForcePitch, 0, 0);
                        
     	if (Throttle < 0) {            
   		AlterAngle.Pitch = -TrackForcePitch;          
      	}
        ForceApplied = AlterAngle.RotateVector(ForceApplied);

Privacy & Terms