Hi,
i have a problem with rotation of a charcter controller in no-horizontale plane. an image will explain better than me ^^ :
this is the code i use to limit rotation:
thanks for your help, see you soon 🙂
i have a problem with rotation of a charcter controller in no-horizontale plane. an image will explain better than me ^^ :
Attachment:
File comment: problem

problem.JPG [ 4.15 KiB | Viewed 1702 times ]
problem.JPG [ 4.15 KiB | Viewed 1702 times ]
this is the code i use to limit rotation:
Code:
//limiting rotation of the body
//applying torque to adjuste the rotation
float timeStepLengthInSeconds = 1 / 60,
timeStepsPerSecond = 60;
float maximumPossibleTorque = 20000;
float torqueAdjustment = 3.f;
float desiredAngle = 0;
float angleNow = body->GetAngle();
float changeExpected = body->GetAngularVelocity() * timeStepLengthInSeconds; //expected angle change in next timestep
float angleNextStep = angleNow + changeExpected;
float changeRequiredInNextStep = desiredAngle - angleNextStep;
float rotationalAcceleration = timeStepsPerSecond * changeRequiredInNextStep;
float torque = rotationalAcceleration * torqueAdjustment;
if ( torque > maximumPossibleTorque )
torque = maximumPossibleTorque;
body->ApplyTorque(torque);
//the rotation must in the range[-0.15, 0.15]
if(body->GetAngle() > 0.15f) body->SetXForm(body->GetPosition(), 0.15f); //0.15 arbirary
if(body->GetAngle() < -0.15f) body->SetXForm(body->GetPosition(), -0.15f);
//applying torque to adjuste the rotation
float timeStepLengthInSeconds = 1 / 60,
timeStepsPerSecond = 60;
float maximumPossibleTorque = 20000;
float torqueAdjustment = 3.f;
float desiredAngle = 0;
float angleNow = body->GetAngle();
float changeExpected = body->GetAngularVelocity() * timeStepLengthInSeconds; //expected angle change in next timestep
float angleNextStep = angleNow + changeExpected;
float changeRequiredInNextStep = desiredAngle - angleNextStep;
float rotationalAcceleration = timeStepsPerSecond * changeRequiredInNextStep;
float torque = rotationalAcceleration * torqueAdjustment;
if ( torque > maximumPossibleTorque )
torque = maximumPossibleTorque;
body->ApplyTorque(torque);
//the rotation must in the range[-0.15, 0.15]
if(body->GetAngle() > 0.15f) body->SetXForm(body->GetPosition(), 0.15f); //0.15 arbirary
if(body->GetAngle() < -0.15f) body->SetXForm(body->GetPosition(), -0.15f);
thanks for your help, see you soon 🙂