Quick question: Object moves different amount each frame despite constant velocity.
Posted: Fri May 12, 2023 5:39 pm
I have a vehicle (but I think the issue exists with normal rigid bodies) in a scene with a constant timestep that I get the position of each frame, to simplfy:
I could end up with output like this:
If the timestep is constant, and the velocity is constant, what is the issue? Why is change in pos not the same every time?
Code: Select all
//world->stepSimulation(deltaMS / 1000.0);
world->stepSimulation(0.05,1,0.05);
if(car->getCurrentSpeedKmHour() > someValue)
//if(car->getRigidBody()->getLinearVelocity().length() > someValue)
{
car->getWheel(0).applyEngineForce(someOtherValue);
car->getWheel(1).applyEngineForce(someOtherValue);
}
btVector3 pos = car->getRigidBody()->getWorldTransform().getOrigin();
float changeInPos = pos.x() - lastPos;
lastPos = pos.x();
std::cout<<"Change in pos: "<<changeInPos<<" Velocity: "<<car->getRigidBody()->getLinearVelocity().x()<<"\n";
Code: Select all
Change in pos: 4.2 Velocity 250.0
Change in pos: 4.1 Velocity 250.0
Change in pos: 3.9 Velocity 250.0
Change in pos: 4.2 Velocity 250.0
Change in pos: 3.7 Velocity 250.0
Change in pos: 4.5 Velocity 250.0
Change in pos: 4.3 Velocity 250.0