Page 1 of 1
Jitter when colliding with a shape encompassing a GravField?
Posted: Wed Jul 13, 2011 2:44 pm
by Spankenstein
I've created a GravitionalField in order to attract objects towards it:
Code: Select all
gravField = new GravitationalField(new InfiniteForceFieldShape(), position, 1000 * 0.5f, 10000, game.Space.BroadPhase.QueryAccelerator);
// Force entities in range to wake up
gravField.ForceWakeUp = true;
I've also enclosed the field in a spherical shape to create a planet with gravity type of effect:
Code: Select all
entity = new Sphere(position, 4f);
The problem is that any shape that comes into contact with the sphere jitters like crazy and does not stick to the surface as intended.
A video showing the problem can be found at the following address:
http://www.youtube.com/watch?v=8xgBwOWxbLM
What might be causing this?
Re: Jitter when colliding with a shape encompassing a GravFi
Posted: Wed Jul 13, 2011 5:10 pm
by Norbo
It looks like there are pretty intense forces being applied. Turning up normal gravity to 50x or 100x without decreasing the time step exhibits similar behavior. The problem is that there's such great acceleration involved that any tiny motion or usually-smooth oscillation is amplified into violent jitter.
A lower cap on the force/acceleration applied should help avoid this problem.
Re: Jitter when colliding with a shape encompassing a GravFi
Posted: Wed Jul 13, 2011 9:10 pm
by Spankenstein
A lower cap on the force/acceleration applied should help avoid this problem.
Are you referring to the 'Multiplier' and 'MaxForce' properties for the GravitationalField class?
If I reduce those values to the point where the jittering no longer occurs, the GravitationField no longer has the strong attractive force I am after.
Is there a way to reduce the max acceleration for all objects, or are you referring to something else entirely?
Re: Jitter when colliding with a shape encompassing a GravFi
Posted: Wed Jul 13, 2011 9:50 pm
by Norbo
The "MaxForce" property is equivalent to capping the acceleration, assuming the objects involved have equal mass. I went ahead and changed it to MaxAcceleration in the development version (
http://bepuphysics.codeplex.com/SourceC ... evelopment) for ease of tuning, though the change was very tiny.
You could also change the field to use a linear falloff instead of a inverse square falloff. That would pull further objects with more force while not requiring immense forces once the objects get close. In the GravitationalField class, there's a commented implementation of this.
Re: Jitter when colliding with a shape encompassing a GravFi
Posted: Wed Jul 13, 2011 10:33 pm
by Spankenstein
I still have the same problems with the build of the latest development fork, but with new errors.
If I use the linear or quadratic falloff then bad things happen when moving the field. NaN errors and all my entities disappear. This didn't happen before.
Re: Jitter when colliding with a shape encompassing a GravFi
Posted: Wed Jul 13, 2011 10:40 pm
by Norbo
I'm surprised it didn't happen before; if the 'singularity' was unprotected, it produces a NaN. You can wrap the impulse calculation in a protective if to stop that. The development version has it now too.
Picking a good/reasonable value for the MaxAcceleration should avoid the jittering. What values and configuration are failing?
Re: Jitter when colliding with a shape encompassing a GravFi
Posted: Wed Jul 13, 2011 11:13 pm
by Spankenstein
What values and configuration are failing?
The threshold for the MaxAcceleration value decreases as the Multiplier value increases, which makes sense.
What doesn't make sense is that if MaxAccelerarion remains constant. but the multiplier changes, jittering can still occur.
For example:
Multiplier = 200 * 0.5f MaxAcceleration = 100 [NO JITTER]
Multiplier = 500 * 0.5f MaxAcceleration = 100 [HEAVY JITTER]
Re: Jitter when colliding with a shape encompassing a GravFi
Posted: Wed Jul 13, 2011 11:19 pm
by Norbo
Multiplier = 200 * 0.5f MaxAcceleration = 100 [NO JITTER]
Multiplier = 500 * 0.5f MaxAcceleration = 100 [HEAVY JITTER]
That would be expected behavior. A max acceleration of 100 is very high (10x normal gravity for the usual scale of objects). With the lower multiplier, the gravity is lower (quite a bit below 100, most likely). With the higher multiplier, the gravity is higher (closer to or hitting the MaxAcceleration).
The trick would be to pick a multiplier which has the desired medium/long range pull, possibly using linear instead of quadratic falloff, and then capping acceleration so near objects don't jitter or approach infinite acceleration as they approach the singularity.
Re: Jitter when colliding with a shape encompassing a GravFi
Posted: Wed Jul 13, 2011 11:29 pm
by Spankenstein
Excellent stuff. I'll get on it.
Thank you for your help
