Re: Jittering and shaking when moving a rigidBody
Posted: Tue Jan 11, 2022 3:49 pm
After a lot of trying I still get the jitter when I set the substeps bigger than 0.
substeps :
motion state :
I only get decent results if I lock the frame rate to 60 fps or disable the substeps (0). Any suggestions?
substeps :
Code: Select all
maxSubsteps = static_cast<int>(delta / (1.f / 60.0f) + 0.5f) + 1;
Code: Select all
void SpaceShipMotionState::getWorldTransform(btTransform& worldTrans) const
{
float yaw, pitch, roll;
auto p = spaceship->MotionStateGetPos();
auto r = spaceship->MotionStateGetRotation();
spaceship->MotionStateGetYawPitchRoll(yaw, pitch, roll);
auto pos = btVector3(p.x, p.y, p.z);
worldTrans.setOrigin(pos);
btQuaternion q;
q.setRotation(btVector3(r.x, r.y, r.z), r.w);
worldTrans.setRotation(q);
//q.setEulerZYX(roll, pitch, yaw);
//worldTrans.setRotation(q);
}
void SpaceShipMotionState::setWorldTransform(const btTransform& worldTrans)
{
auto p = worldTrans.getOrigin();
glm::vec3 pos = { p.x(), p.y(), p.z() };
spaceship->MotionStateSetPosition(pos);
static glm::vec4 Rotation;
auto q = worldTrans.getRotation();
btVector3 v = q.getAxis();
Rotation.x = v.x();
Rotation.y = v.y();
Rotation.z = v.z();
Rotation.w = q.getAngle();
spaceship->MotionStateSetRotation(Rotation);
static btScalar yaw;
static btScalar pitch;
static btScalar roll;
worldTrans.getBasis().getEulerZYX(roll, pitch, yaw, 1);
yaw = glm::degrees(yaw);
pitch = glm::degrees(pitch);
roll = glm::degrees(roll);
spaceship->MotionStateSetYawPitchRoll(yaw, pitch, roll);
}