max body or geom speed

Topics: User Forum
Feb 5, 2009 at 1:22 AM
is there any way of setting a max speed that a body can reach?

i cant seem to figure out the code to do it my self and was wondering if the engine could do it
Feb 5, 2009 at 4:21 AM
After an inspection (more of a skimming) of the Body class, it seems that there is no way to do that... I motion that that be added to the feature list! in fact, i could do it myself if you want (i think, lemme check the code like how bodies are updated)!
Feb 5, 2009 at 5:02 AM
you seriosly have no idea how happy that would make me lol

this is the code i am now trying to use to get my ship to be limited

                Vector2 CurrentOffset = m_Body.GetVelocityAtLocalPoint(Vector2.Zero);

                float MyMulti = 1;
                if (CurrentOffset.LengthSquared() > m_Data.MaxSpeed)
                    float CurrentAngle = g_Math.GetInstance.AngleFromVectorRadians(CurrentOffset);
                    float WantedAngle = g_Math.GetInstance.AngleFromVectorRadians(in_Input);

                    float Diff = CurrentAngle - WantedAngle;

                    MyMulti = g_Math.GetInstance.PercentMultiplierCapped((float)Math.PI, (float)Diff); //To make a multiplier going from 0 to 1
                //Apply physics force
                m_Body.ApplyForce(((in_Input*m_Data.Acceleration)*MyMulti) * ((float)in_GameTime.ElapsedRealTime.Milliseconds / 1000));

just being able to set a limit in the physics would be such a blessing then i wouldnt have to worry about so much force and stuff

thanks heaps in advance :)

Feb 5, 2009 at 11:22 PM
does anyone know the changes i would need to make to make this work?
Feb 5, 2009 at 11:39 PM
Well, you could limit the velocity of the body by checking it on each update and capping it. This will however give you weird results as the velocity will never get over the defined limit.
Creating something like terminal velocity can be accomplished by using the linear drag coefficient. Example: if you set the Simple Sample Demo 2 to have a gravity of y=150 and the linear drag of the ball to 2, you will have a terminal velocity of y=75
Feb 7, 2009 at 6:41 AM
will this work even with a gravity of 0,0 ?

and what would happen if i did happen to make something overspeed?

is there anyway with some math that i could make a simple _MaxSpeedPerSecond value and corrasponding functions??
being able to just set geom max speeds would be so good :)
Feb 7, 2009 at 1:39 PM
Yes, Linear drag would also work without gravity, but then it would not be like terminal velocity as it's defined by the downward pull of gravity force.
If your body is applied a large force it would accelerate to a high speed and slow down (at the rate of the drag coefficient).

As I said before, you could just cap the velocity of the geom to set it's max speed. But it depends on what you use it for.
Feb 7, 2009 at 2:36 PM
A little side-question about the linear drag. Doesn't mass influence the force of linear drag? Like how a plastic ball falls down slower than a concrete one.
Feb 7, 2009 at 2:49 PM

Again, if I use the example from above and you have a vector of 0,150 force in gravity, a body of mass 1 and linear drag of 2 you would have a velocity vector of 0,~75 (terminal velocity). But if you increase the mass to 2, the velocity vector would get multiplied by 2 and thus be a vector of 0,~150.
Feb 7, 2009 at 5:55 PM
But then I would also expect a heavier (higher mass) object falling faster (accelerating faster) than it's equal lighter one. But that doesn't seem to happen...?
Feb 7, 2009 at 6:12 PM
You are tempting me to explain something about what Issac Newton said here. I'll try not to. :)

If you have a piano and a feather falling from a tall building, obviously the piano will fall faster than the feather. (providing you have gravity force) But if you have no wind resistance (linear drag) the 2 things will fall with exactly the same rate (velocity).

The physics engine is built on Newton's laws of physics. If you create 2 bodies and set their linear drag to 0 and their mass to 1 and 1000. They will indeed fall with the same velocity.
If you however set the linear drag on both of them to be 2, then the one with the highest mass will accelerate the quickest.
Feb 7, 2009 at 6:25 PM
Edited Feb 7, 2009 at 6:27 PM
Hehe don't worry, I understand that law. :) 
The point was, I was testing that law, and didn't noticed any difference in falling speed for two objects with different mass. But I forgot to test the linear drag which was too low to create a sufficient difference. After I changed it on 2, they indeed fell at different speeds.
Thanks :)
Feb 7, 2009 at 8:37 PM
No problem jordos.
A lot of people would probably need that information to understand Farseer Physics (and physics in general) better.