Page 1 of 1

Smoothing out sudden changes in velocity with a LinearMotor?

Posted: Fri Jul 06, 2012 11:02 pm
by Spankenstein
I can pick up and shake objects using a linear motor. The settings for the motor depend on the mass of the entity in order to keep the response the same across varying masses.

Code: Select all

            linearMotor.Settings.Servo.SpringSettings.StiffnessConstant = 60000f * Entity.Mass;
            linearMotor.Settings.Servo.SpringSettings.DampingConstant = 900f * Entity.Mass;
            linearMotor.Settings.MaximumForce = 10000f * Entity.Mass;
To shaking the entity I use the current position of the mouse each frame

Code: Select all

            var cursorRay = cursor.Ray;

            Vector3 goalPosition = grabSpring.GoalPosition;
            Vector3 position = cursorRay.Origin + cursorRay.Direction * grabDistance;

            grabSpring.GoalPosition = goalPosition;
The problem is that if I shake the mouse side to side very quickly then it produces unstable violent changes in the entity's velocity.

How could I reduce the force exerted onto the entity without affecting the strength of the motor?

I have considered interpolating between mouse positions and setting the goal position using the interpolated values but I think this might look a little sluggish.

Re: Smoothing out sudden changes in velocity with a LinearMo

Posted: Fri Jul 06, 2012 11:26 pm
by Norbo
If the 'true motion' is extremely violent, any sort of smoothing will have a byproduct of sluggishness/inaccuracy because it's not faithful to the violence of the motion. There's a bit of an unavoidable tradeoff there.

So:
How could I reduce the force exerted onto the entity without affecting the strength of the motor?
This isn't really a consistent concept. Reducing the force on the entity necessarily weakens the control system (directly, by changing motor parameters, or indirectly, but adjusting the input to the motor).

It sounds like the actual problem is that the 'true motion' is so violent that the simulation can't stay perfectly stable with the forces required to follow it exactly. At that point, there are a few options:
1) If the motion is just too strong for objects in general, weakening it in some way would be a good idea. Reducing the spring constants or maximum force would help. Using a nonzero motor.Settings.Servo.BaseCorrectiveSpeed might be able to achieve something closer to your desired motion while avoiding hyper-rigid springs. Using base corrective speed will make an object converge to the goal with an attempted-constant speed on top of whatever spring-sourced velocity goal there is. This might help small, fast motions feel like they converge faster than the error-responding spring correction alone without requiring a lot of force because springs apply less force at smaller distances.
2) If the motion is just too strong for objects in general, increase the accuracy of the simulation by taking more, shorter time steps and increasing the iteration count.
3) Is the simulation having a hard time because of some particular difficult part of the simulation? Is the mouse ripping apart an articulated system? If so, reducing the violence applied to objects involved in articulated structures might be a good idea (a conditional reduction in spring constants/force).

Re: Smoothing out sudden changes in velocity with a LinearMo

Posted: Sat Jul 07, 2012 8:56 am
by Spankenstein
Setting the 'BaseCorrectiveSpeed' doesn't seem have any effect, even when in Servo mode.

Code: Select all

linearMotor.Settings.Servo.BaseCorrectiveSpeed = 1f;
However setting the 'MaxCorrectiveVelocity' does stabilise things considerably and still allows for believable shaking.

Code: Select all

            
linearMotor.Settings.Servo.MaxCorrectiveVelocity = 50f;
Does this setting need to be scaled by the mass of the entity for shaking heavier objects?

Re: Smoothing out sudden changes in velocity with a LinearMo

Posted: Sat Jul 07, 2012 4:04 pm
by Norbo
Setting the 'BaseCorrectiveSpeed' doesn't seem have any effect, even when in Servo mode.
The BaseCorrectiveSpeed will likely only be noticeable if the spring is not otherwise strong enough to immediately snap to the goal (or exceed the MaxCorrectiveVelocity).
Does this setting need to be scaled by the mass of the entity for shaking heavier objects?
Nope; it is a velocity cap, not a force cap.

Re: Smoothing out sudden changes in velocity with a LinearMo

Posted: Sat Jul 07, 2012 4:31 pm
by Spankenstein
Brilliant. Another physics problem solved. Thank you! :D