fixed throwing and meter

This commit is contained in:
Jeena 2014-01-10 17:25:46 +01:00
parent 86dcdf92df
commit 3a07d946b0
4 changed files with 84 additions and 45 deletions

View file

@ -269,7 +269,15 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
var body = item.body;
body.SetAwake(true);
body.ApplyImpulse(new Box2D.Common.Math.b2Vec2(x * 3, -y * 3), body.GetPosition());
body.ApplyImpulse(
new Box2D.Common.Math.b2Vec2(
x * Settings.MAX_THROW_FORCE,
-y * Settings.MAX_THROW_FORCE * 2 // 2 is to throw higher then far
),
body.GetLocalCenter()
);
body.SetAngularVelocity(5);
};
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {

View file

@ -10,6 +10,7 @@ function (Parent, Box2D, Settings) {
this.options = options;
Parent.call(this, physicsEngine, uid);
this.createFixture();
this.body.ResetMassData();
}
Item.prototype = Object.create(Parent.prototype);
@ -28,16 +29,21 @@ function (Parent, Box2D, Settings) {
Item.prototype.createFixture = function () {
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
var w = this.options.width / 2 / Settings.RATIO;
var h = this.options.height / 2 / Settings.RATIO;
itemShape.SetAsOrientedBox(w, h, new Box2D.Common.Math.b2Vec2(0, -h));
var w = this.options.width / Settings.RATIO;
var h = this.options.height / Settings.RATIO;
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(h/2)));
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
fixtureDef.shape = itemShape;
fixtureDef.density = Settings.ITEM_DENSITY;
var offset = 4,
factor = 80;
var density = ((this.options.weight + offset) / this.options.width / this.options.height) * factor;
fixtureDef.density = density;
fixtureDef.friction = Settings.ITEM_FRICTION;
fixtureDef.restitution = Settings.ITEM_RESTITUTION;
fixtureDef.isSensor = false;
this.body.CreateFixture(fixtureDef);
}