Set an object max speed

Hi everyone,

I’m still a newbie in Corona and I’m currently stuck with the following problem. I hope any of you can help me out.

I use applyLinearImpulse to different objects in my game, but since some are smaller than others the smaller ones reach a speed way higher than I want. And if I reduce the amount of the linear impulse the bigger ones end up at a very low speed. 

Is there a way I can set a maximum speed for the objects in my game that in some way no matter the amount of force they receive they don’t go beyond the maximum speed I set?

Thanks a lot for your wisdom.

you should probably scale the impulse based on the .mass of the body

setting a higher .linearDamping might help too (essentially mimics “drag”, making it harder and harder to accelerate)

finally, if none of that works, you can manually clamp the velocity to a chosen hard maximum (you’ll have to do it repeatedly, like in an enterFrame loop), see my post in this thread (not exactly what you need as is, but has all the pieces, just add an “if” test to check if exceeds maximum before coercing): http://forums.coronalabs.com/topic/38005-pushing-object-at-constant-velocity/

hth

I answered a similar question here some time ago: http://forums.coronalabs.com/topic/51384-apply-impulse-applies-floating-point-force-instead-of-constant/

I hope this will help.

Note: My answer addresses the need to apply forces so that they are ‘mass relative’ and give a consistent response for different sized objects.

you should probably scale the impulse based on the .mass of the body

setting a higher .linearDamping might help too (essentially mimics “drag”, making it harder and harder to accelerate)

finally, if none of that works, you can manually clamp the velocity to a chosen hard maximum (you’ll have to do it repeatedly, like in an enterFrame loop), see my post in this thread (not exactly what you need as is, but has all the pieces, just add an “if” test to check if exceeds maximum before coercing): http://forums.coronalabs.com/topic/38005-pushing-object-at-constant-velocity/

hth

I answered a similar question here some time ago: http://forums.coronalabs.com/topic/51384-apply-impulse-applies-floating-point-force-instead-of-constant/

I hope this will help.

Note: My answer addresses the need to apply forces so that they are ‘mass relative’ and give a consistent response for different sized objects.