void AHoverPawn::TurnActor(float AxisValue)
{
FVector Cv = Car->GetPhysicsLinearVelocity();
FVector Fv = Car->GetForwardVector();
float f = FVector::DotProduct(Cv, Fv);
if (f > 0)
{
Car->AddTorque(FVector(0, 0, 1000000 * AxisValue));
FVector Rv = Car->GetRightVector();
FVector V = Car->GetComponentVelocity();
float dotP = FVector::DotProduct(Rv, V);
float invertValue = dotP * -1;
float next = invertValue * 4000;
FVector getRv = Car->GetRightVector();
Car->AddForce(getRv * next);
Car->AddForce(getRv * next);
}
else
{
Car->AddTorque(FVector(0, 0, 900000 * AxisValue *-1));
FVector Rv = Car->GetRightVector();
FVector V = Car->GetComponentVelocity();
float dotP = FVector::DotProduct(Rv, V);
float invertValue = dotP * -1;
float next = invertValue * 4000;
FVector getRv = Car->GetRightVector();
Car->AddForce(getRv * next);
}
}
this rotates my pawn, but the problem is it rotates really fast because of the input, and then goes out of control. I got the Pawns angular velocity and used the FVector::Size() method which returns a float, The angular rotation velocity was going up when ever I held down D. In order to bring it down to 0, I would have to hold down A as it spins out of control.
How can I stop the Pawn from rotating out of control?
It is a
Car = CreateDefaultSubobject<UBoxComponent>(TEXT("CarMesh"));
Physics box component with physics enabled.
The pawn is hard to control, since it rotates too fast.