Box2d Flash AS3 (1.4.3 released)

For shooting a ball I would use a single impulse. You may have a very heavy body, look at the mass. Also the body may be frozen if it is outside the world bounds. And you might have a very large gravity value.

Look at the ApplyForce example in the test-bed.
With the current build 1.4.3 I can only get things to move if I apply a rather large impulse.

If I have a box:

Code:
var bd1:b2BoxDef = new b2BoxDef();
bd1.extents.Set(8 / m_physScale, 15 / m_physScale);
bd1.density = 2.0;
bd1.restitution = 0.1;
bd1.friction = 1.0;


I need to do something like this to make it move:

Code:
player.WakeUp();
player.ApplyImpulse(new b2Vec2(20000,0), player.GetCenterPosition());


In version 1.4.2 an impulse of new b2Vec2(50,0) would work.

As far as I can see the only difference is that b2_lengthUnitsPerMeter is 30.0 rather than 1.0. However setting it back to 1.0 doesn't seem to affect the figures mentioned above. I understand that using pixel units rather than meters will result in large forces/torques required but this seems massively different.

Have I missed something?

BTW: great work!
What is the value of m_physScale?
Erin Catto wrote:
What is the value of m_physScale?

Hi Erin, the value is:
Code:
public var m_physScale:Number = 1;

Not sure if these are relevant too:
Code:
public var m_iterations:int = 10;
public var m_timeStep:Number = 1/30;
With those numbers:

mass = 2 * 16 * 30 = 960

velocity = impulse / mass = 20000 / 960 = 20.8 units per second

Is this what you are seeing?

Apart from friction, contact, or damping, the box should move its length in one second. That's kind of slow.

I think that skatehead changed m_phyScale in version 1.4.3, so that might explain the difference.
Starting to make sense now - that's pretty much what I'm seeing.

Guess I thought I was doing something wrong as I had to use such massive forces to move anything. But I guess that as the units have been changed to work with pixels instead of metres everything is bigger.

Thanks

Al
Hi all,

I have been playing around with box2dflash.

I experience extremely bad performance on my PC if the flash player 9 window loses focus.

For example, I right click on my Taskbar (Windows XP) and then try left clicking on Task Manager.

It shows that the CPU utilisation is 95%. It seems like Flash Player is getting most of the CPU cycles...coz my other Window Apps couldn't compete with it.

Anybody knows why?
Al: Sorry about the confusion, I'm still trying to decide whether or not I should use pixel units in the examples, or if I should try adding a layer of abstraction so the end user can use pixel units but use meter units in the simulation without bothering them with the physScale variable.

This should answer your question armage:

raigan wrote:
t_anjan wrote:
I just noticed that the PhysTest.fla has a frame rate of 120 fps. The flash player uses 90% of CPU power continuously (as seen in the task manager). Normal flash movies and games run at 12 fps, if I'm not mistaken.

What's the guarantee that the swf will run smoothly on older computers?


I don't think many games run at 12fps -- that's just the default setting in the authoring environment. I always use 60,90, or 120fps and use code internally to keep the game running as smoothly as possible.


Basically, Flash doesn't try hard enough to keep up with the framerate you set, so you have to use a much higher framerate, and limit it yourself by wasting cycles.
It helps a lot with performance, especially in the browser, but it does have the tradeoff of potentially making other applications unresponsive while it's running in the standalone player.
skatehead wrote:
Al: Sorry about the confusion, I'm still trying to decide whether or not I should use pixel units in the examples, or if I should try adding a layer of abstraction so the end user can use pixel units but use meter units in the simulation without bothering them with the physScale variable.


Hey - no problem. It's now starting to make sense after Erin went through the maths above.

EDIT: my head hurts now... now I've just read this http://www.box2d.org/forum/viewtopic.php?f=4&t=171 and meter's really do seem to make more sense - having to use massive forces and torques to shift things will lead to a lot of confusion.
skatehead wrote:
Basically, Flash doesn't try hard enough to keep up with the framerate you set, so you have to use a much higher framerate, and limit it yourself by wasting cycles.
It helps a lot with performance, especially in the browser, but it does have the tradeoff of potentially making other applications unresponsive while it's running in the standalone player.


How exactly does one limit the framerate by wasting cycles? Or, does Box2D do it by itself?

So, can I take it for granted that the 120 fps SWF will play without problems on a browser of any old computer?

Original thread: https://box2d.org/forum/viewtopic.php?t=47