I can climb ramps (in case you were wondering)

Like others, I was a little disapointed that I couldn’t get my tank climbing ramps due the the way the project was set up. I understand that to do it properly you need a physics based model, but enabling physics resuts in my tank blowing up, or the level floor tilting, or the turret balancing on top of the capsule and, essentailly, not working. I tried every setting I could, then decided to just hack my code (but hey, it works).

Essentially I just made the move function raise the tank in the Z axis a bit (based on a new ClimbSpeed I included), then throw the tank back down to the ground (in case the Z change was too much or you drove of the edge of a platform). This is my move function:

void ATank::Move(float Value)
	FVector MoveSpeed = FVector::ZeroVector;
	MoveSpeed.Z = abs(Value) * ClimbSpeed * UGameplayStatics::GetWorldDeltaSeconds(this); // works in forward and reverse
	MoveSpeed.X = Value * Speed * UGameplayStatics::GetWorldDeltaSeconds(this);
	AddActorLocalOffset(MoveSpeed, true); // Move forward and up (in case there is a ramp to climb)...
	MoveSpeed = FVector::ZeroVector;
	MoveSpeed.Z = -10 * ClimbSpeed * UGameplayStatics::GetWorldDeltaSeconds(this);
	AddActorLocalOffset(MoveSpeed, true); // ...and fall down to the floor again.

You could vary the “10” in the penultimate line to change the fall rate when dropping off an edge if you think it is too fast.

I have a Speed set to 750 and a ClimbSpeed set to 200, with which I can climb 15 degree slopes. You can increase the ClimbSpeed if you want to be able to climb steeper slopes, or reduce it to flatten the slope ange yoiu can climb.

1 Like

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

Privacy & Terms