Game Development Reference
In-Depth Information
Also, looking at the text in the output window confirms what we saw in the movie.
The rightmost sphere reached pixel 80, moving up by 330 pixels, the middle sphere
moved by only 2 pixels, and the leftmost sphere did not move at all.
Sphere 0:410
Sphere 1:408
Sphere 2:80
Ok, let's say probably the spheres are too heavy to react to the forces (but remember
the rightmost sphere jumped quite high), so we are reducing their density from 2 to
1 in the sphere function:
private function sphere(pX:int,pY:int,r:Number):b2Body {
var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.position.Set(pX/worldScale,pY/worldScale);
bodyDef.type=b2Body.b2_dynamicBody;
bodyDef.userData=pY;
var circleShape:b2CircleShape;
circleShape=new b2CircleShape(r/worldScale);
var fixtureDef:b2FixtureDef=new b2FixtureDef();
fixtureDef.shape=circleShape;
fixtureDef.density=1;
fixtureDef.restitution=0.4;
fixtureDef.friction=0.5;
var theSphere:b2Body=world.CreateBody(bodyDef);
theSphere.CreateFixture(fixtureDef);
return theSphere;
}
Let's test the movie again and see what happens:
Sphere 0:410
Sphere 1:401
Sphere 2:80
The first thing which should come to your notice is that the rightmost sphere reached
exactly the same height as before, no matter if the density changed.
That's because SetLinearVelocity just sets the linear velocity of a body, no matter
of its mass or previous velocity. It just sets the velocity. Full stop!
On the other hand, the middle sphere jumped a bit more than before, so this means
ApplyImpulse depends on the mass of a body.
 
Search WWH ::




Custom Search