i am making a battle tank game with the help of a course on udemy. I have created a pawn = tank. I want to rotate my tank wheels to rotate whenever i pass the throttle value to it. The wheels do not have any collision and i have created a suspension using physics constraint. The tank wheel is a staticmeshcomponent which is a part of of tank suspension.
The problem is i have written the c++ code and the wheels rotate perfectly and realistically when i apply throttle value. they rotate full upto 360 in X and Z axis(Roll and Yaw). But they rotate between -90 to +90 in pitch value which is what i need for wheels to rotate. The wheels do not rotate further than 90 or -90.
void UTankWheels::BeginPlay()
{
Super::BeginPlay();
}
void UTankWheels::Spin(float RotationSpeed)
{
float Spin = RotationSpeed * MaxDegreesPerSecond * GetWorld()->GetDeltaSeconds();
auto RotateAmnt = FMath::Clamp<float>(Spin, -1, 1);
auto NewRotation = GetRelativeTransform().GetRotation().Rotator().Pitch;
auto Rotate = GetRelativeRotation().Pitch + RotateAmnt;
FRotator Rotation = FRotator(Rotate, 0, 0);
UE_LOG(LogTemp, Warning, TEXT("rotation: %f"), Rotation.Pitch)
SetRelativeRotation(Rotation)
}
I’ve tried everything…AddLocalRotation, DeltaSeconds but no luck…i want to try quaternions next but don’t know anything about it…
link to my project https://drive.google.com/file/d/1jBLQZwKzJfoVmG4smLDuWFIg1Mhmx0kH/view?usp=sharing