Jerky vehicle movment.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Jerky vehicle movment.

Post by lazy »

Hi again

My vehcile moves a bit jerky. Don't know why. Some frames it seems to stall. (not much, but enough to be irritating)
Can it be the wheels getting stuck in the car body? The rest of the game moves smoothly. ( I've added animated object that move around the world to be sure )

This video shows what I mean. Sorry for the bad quality :P And I hope you have the codec.

http://www.scavenger.se/vehicle.avi
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Jerky vehicle movment.

Post by Norbo »

That's odd. My first guess would be continuous collision detection. The car body may be thinking it's going to hit something based on its velocity and only integrates forward enough to check for that collision rather than all the way through the step, leading to an unsightly jig.

Does it still happen if you change the CCD mode or turn it off?
To use linear continuous collision detection only:

Code: Select all

space.simulationSettings.collisionDetection.collisionDetectionType = CollisionDetectionType.linearContinuous;
To turn it off:

Code: Select all

space.simulationSettings.collisionDetection.collisionDetectionType = CollisionDetectionType.discreteMPRGJK;
Other possibilities could include something to do with timestepping, though I'm not sure what yet.
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Jerky vehicle movment.

Post by lazy »

Thanks for the fast answers!

I run at a stable 30fps.

I'll try your suggestions right away!
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Jerky vehicle movment.

Post by lazy »

I get the same result with the two collision detection types. =(
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Jerky vehicle movment.

Post by Norbo »

Alrighty, that's good and bad. The good is that CCD isn't bugged, the bad is that I don't know exactly what's wrong yet :D

You said you had a purely animated shape running around; it doesn't have any jigs whatsoever when the car jigs? Is its position updated in the same area as the space-update?

Are you currently using internalTimeStepping?

Right now I'm just trying to gather information, since I'm not exactly sure what is causing it.
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Jerky vehicle movment.

Post by lazy »

Yes I added a simple model that just moves from one side of the screen to the other and back. It moves smoothly.
It is updated with the same dt as the space.

The time step duration is set to be the same as the screen refresh rate. I've tried both 1/60 and 1/30. The game waits for the vsync.
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Jerky vehicle movment.

Post by lazy »

I've tried both on windows and xbox360.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Jerky vehicle movment.

Post by Norbo »

When you say it is updated with the same dt as the space, is it a flat 1/30 (or 1/60) each call to Update, or are you passing the elapsedGameTime.TotalSeconds?

There may be a frame stutter which the animated object deals with by moving further due to a longer elapsed time, while the engine only moves forward 1/30 (or 1/60) of a second. If this is the case, you can enable internal time stepping:

Code: Select all

space.simulationSettings.timeStep.useInternalTimeStepping = true;
The engine will try to simulate the space.update passed-in value by taking a number of 1/30 (or 1/60) steps. If there's time left, it will interpolate some of the entity's properties to avoid a jerky appearance. Interpolated properties include orientationQuaternion/orientationMatrix, centerPosition, and worldTransform (so you'd have to use one of them to set the graphics transform instead of an "internal" property like internalCenterPosition).
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Jerky vehicle movment.

Post by lazy »

Now when I increased the velocity of the animated object I see it is moving like the car.
So there's nothing wrong with the physics.

Sorry...

Thanks for your help!
I hope I didn't waste too much of your time =)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Jerky vehicle movment.

Post by Norbo »

No problem :)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Jerky vehicle movment.

Post by Norbo »

By the way, it looks a lot like a garbage collector jig (particularly if you notice it more on the Xbox than the PC). Running a release-compiled version through CLR profiler might provide some helpful debugging information for you. That, and the "XNA Framework Remote Performance Monitor for Xbox 360" that comes with XNA Game Studio would help narrow things down.
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Jerky vehicle movment.

Post by lazy »

I've run the performance monitor and made sure no allocations are made after initialization.
So, it's not the GC.

I'll try the CLR profiler
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Jerky vehicle movment.

Post by lazy »

Found it!
A very simple error. But I've been looking for it for ages!

I had both sync to vsync AND fixed time step enabled in my Xna.FrameWork.Game
Now it runs smoooth!

I'm soooo happy =)
Post Reply