swf preview (might need a second to load)
for some reason im getting this strange problem that my bodies arn't colliding. I'm new to the whole box2d thing, so forgive my bad coding. Basicly i have it set up that the bike class (currently just a circle) creates it s self and the 'ground' creates itself in another class. But the world is in a 3rd class (public static var). it all seems logical and should work, but it doesn't. any ideas?
for some reason im getting this strange problem that my bodies arn't colliding. I'm new to the whole box2d thing, so forgive my bad coding. Basicly i have it set up that the bike class (currently just a circle) creates it s self and the 'ground' creates itself in another class. But the world is in a 3rd class (public static var). it all seems logical and should work, but it doesn't. any ideas?
Code:
public class Bike
{
public var density:Number = 0.5
public var grip:Number = 1
public var bouncyness:Number = 0.3
public var rearWheel:b2Body;
public function Bike()
{
makeBike ()
rearWheel.ApplyForce (new b2Vec2 (0, 100), rearWheel.GetPosition())
}
private function makeBike():void
{
var wheelShape:b2CircleShape = new b2CircleShape (20 / Vals.RATIO)
var wheelFixture:b2FixtureDef = new b2FixtureDef()
wheelFixture.density = density
wheelFixture.friction = grip
wheelFixture.restitution = bouncyness
wheelFixture.shape = wheelShape
var rearWheelDef:b2BodyDef = new b2BodyDef ()
rearWheelDef.position.Set (0, 0)
rearWheelDef.type = b2Body.b2_dynamicBody
rearWheel = Vals._world.CreateBody (rearWheelDef)
rearWheel.CreateFixture (wheelFixture)
}
}
{
public var density:Number = 0.5
public var grip:Number = 1
public var bouncyness:Number = 0.3
public var rearWheel:b2Body;
public function Bike()
{
makeBike ()
rearWheel.ApplyForce (new b2Vec2 (0, 100), rearWheel.GetPosition())
}
private function makeBike():void
{
var wheelShape:b2CircleShape = new b2CircleShape (20 / Vals.RATIO)
var wheelFixture:b2FixtureDef = new b2FixtureDef()
wheelFixture.density = density
wheelFixture.friction = grip
wheelFixture.restitution = bouncyness
wheelFixture.shape = wheelShape
var rearWheelDef:b2BodyDef = new b2BodyDef ()
rearWheelDef.position.Set (0, 0)
rearWheelDef.type = b2Body.b2_dynamicBody
rearWheel = Vals._world.CreateBody (rearWheelDef)
rearWheel.CreateFixture (wheelFixture)
}
}
Code:
private function addPointsShape(l):void
{
var Friction:Number = 0.5
var Elasticity:Number = 0
var Def:b2PolygonShape = new b2PolygonShape ()
Def.SetAsVector (points, l)
var fixtureD:b2FixtureDef = new b2FixtureDef ()
fixtureD.friction = Friction
fixtureD.restitution = Elasticity
fixtureD.density = 1.0
fixtureD.shape = Def
var BodyDef:b2BodyDef = new b2BodyDef();
BodyDef.position.Set (0, 0);
BodyDef.type = b2Body.b2_staticBody
var Body:b2Body = Vals._world.CreateBody(BodyDef);
Body.CreateFixture (fixtureD)
}
{
var Friction:Number = 0.5
var Elasticity:Number = 0
var Def:b2PolygonShape = new b2PolygonShape ()
Def.SetAsVector (points, l)
var fixtureD:b2FixtureDef = new b2FixtureDef ()
fixtureD.friction = Friction
fixtureD.restitution = Elasticity
fixtureD.density = 1.0
fixtureD.shape = Def
var BodyDef:b2BodyDef = new b2BodyDef();
BodyDef.position.Set (0, 0);
BodyDef.type = b2Body.b2_staticBody
var Body:b2Body = Vals._world.CreateBody(BodyDef);
Body.CreateFixture (fixtureD)
}
Code:
public class Vals
{
public static var _world:b2World = new b2World (new b2Vec2 (0, 9.8), true)
public static var RATIO:Number = 40
{
public static var _world:b2World = new b2World (new b2Vec2 (0, 9.8), true)
public static var RATIO:Number = 40
Code:
public class Stepper extends Sprite
{
public function Stepper()
{
debugDraw ()
this.addEventListener (Event.ENTER_FRAME, step)
}
private function step(e:Event):void
{
Vals._world.Step (1 / 90, 10, 10)
Vals._world.ClearForces ()
Vals._world.DrawDebugData ()
}
private function debugDraw():void
{
var mdebugDraw : b2DebugDraw = new b2DebugDraw();
mdebugDraw.SetSprite (this)
mdebugDraw.SetDrawScale(Vals.RATIO);
mdebugDraw.SetFillAlpha(0.5);
mdebugDraw.SetLineThickness(2.0);
mdebugDraw.SetFlags(1);
Vals._world.SetDebugDraw(mdebugDraw);
}
{
public function Stepper()
{
debugDraw ()
this.addEventListener (Event.ENTER_FRAME, step)
}
private function step(e:Event):void
{
Vals._world.Step (1 / 90, 10, 10)
Vals._world.ClearForces ()
Vals._world.DrawDebugData ()
}
private function debugDraw():void
{
var mdebugDraw : b2DebugDraw = new b2DebugDraw();
mdebugDraw.SetSprite (this)
mdebugDraw.SetDrawScale(Vals.RATIO);
mdebugDraw.SetFillAlpha(0.5);
mdebugDraw.SetLineThickness(2.0);
mdebugDraw.SetFlags(1);
Vals._world.SetDebugDraw(mdebugDraw);
}