Quote:
if (s is Disco) {
var v:b2Vec2 = body.GetLinearVelocity().Copy();
if (v.Length() > 8) {
v.Multiply(.8);
}
body.SetLinearVelocity(v);
}
if you are willing to treat max velocity as X and Y separately,
b2Vec2 has a built in function MaxV, which you would call on enter frame sending it a b2Vec2, with appropriate x and y
or you could do the function your self i suppose, MaxV is a simple (but condenced) if statement to either use the speed that exsists or the max speed
x = x > b.x ? x : b.x;
y = y > b.y ? y : b.y;
to apply the same sort of formula to both X and Y combined velocity, would be something like this.
assuming that you wanted to limit it to keep going at the max speed after it reaches the max speed, this would be most accurate.
Code:
var v:b2Vec2 = body.GetLinearVelocity().Copy();
var maxSpeed:Number = 8
if (v.Length() > 8) {
var percentage = 8/v.Length();
v.x *= percentage
v.y *= percentage
body.SetLinearVelocity(v);
}
what i find interesting is that you use .Copy();
it doesn't seem necessary in this case.
so if you are looking for a bit more speed, consider taking that off.
if that's preventing what i think its preventing, you may not need SetLinearVelocity(v), once Copy() is removed.
seems like the reason to copy the variable is to not edit the original.
good luck.