fixed item throw interface of ragdoll fixes #93

This commit is contained in:
logsol 2015-02-07 14:30:55 +01:00
parent 15e4b2825f
commit 5caa21f453
5 changed files with 19 additions and 24 deletions

View file

@ -130,15 +130,19 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
}; };
Item.prototype.throw = function(options, carrierVelocity) { Item.prototype.throw = function(options, carrierVelocity) {
var body = this.body; this.accelerateBody(this.body, options, carrierVelocity);
};
Item.prototype.accelerateBody = function(body, options, carrierVelocity) {
body.SetAwake(true); body.SetAwake(true);
var vector = new Box2D.Common.Math.b2Vec2( var vector = new Box2D.Common.Math.b2Vec2(
options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x, options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x,
-options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y -options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y
); );
this.body.SetLinearVelocity(vector);
body.SetLinearVelocity(vector);
body.SetAngularVelocity(-options.av * Settings.MAX_THROW_ANGULAR_VELOCITY); body.SetAngularVelocity(-options.av * Settings.MAX_THROW_ANGULAR_VELOCITY);
}; };

View file

@ -334,21 +334,13 @@ function (Parent, Box2D, Settings, Nc) {
this.limbs.head.SetAngle((this.options.grabAngle || 0) * direction); this.limbs.head.SetAngle((this.options.grabAngle || 0) * direction);
}; };
RagDoll.prototype.throw = function(x, y) { RagDoll.prototype.throw = function(options, carrierVelocity) {
Parent.prototype.throw.call(this, x, y); Parent.prototype.throw.call(this, options, carrierVelocity);
var limbDampingFactor = 1;
for(var name in this.limbs) { for(var name in this.limbs) {
var body = this.limbs[name]; var body = this.limbs[name];
body.SetAwake(true);
var vector = new Box2D.Common.Math.b2Vec2( this.accelerateBody(body, options, carrierVelocity);
x * Settings.MAX_THROW_FORCE * limbDampingFactor / this.options.weight,
-y * Settings.MAX_THROW_FORCE * limbDampingFactor / this.options.weight
);
body.SetLinearVelocity(vector);
// body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x);
} }
}; };

View file

@ -87,18 +87,13 @@ function (Parent, Box2D, Settings) {
// FIXME: implement body flip if necessary // FIXME: implement body flip if necessary
}; };
Skateboard.prototype.throw = function(x, y) { Skateboard.prototype.throw = function(options, carrierVelocity) {
Parent.prototype.throw.call(this, x, y); Parent.prototype.throw.call(this, options, carrierVelocity);
for (var i = 0; i < this.wheels.length; i++) { for (var i = 0; i < this.wheels.length; i++) {
var body = this.wheels[i]; var body = this.wheels[i];
body.SetAwake(true);
var vector = new Box2D.Common.Math.b2Vec2( this.accelerateBody(body, options, carrierVelocity);
x * Settings.MAX_THROW_FORCE / this.options.weight,
-y * Settings.MAX_THROW_FORCE / this.options.weight
);
body.SetLinearVelocity(vector);
} }
}; };

View file

@ -44,8 +44,8 @@ define([
Level.prototype.createItem = function(uid, options) { Level.prototype.createItem = function(uid, options) {
switch(options.type) { switch(options.type) {
//case 'skateboard': case 'skateboard':
// return new Skateboard(this.engine, uid, options); return new Skateboard(this.engine, uid, options);
case 'ragdoll': case 'ragdoll':
return new RagDoll(this.engine, uid, options); return new RagDoll(this.engine, uid, options);
case 'rube': case 'rube':

View file

@ -14,7 +14,11 @@ function (Nc, childProcess) {
this.fork = null; this.fork = null;
try { try {
this.fork = fork('channel.js'); this.fork = fork('channel.js'
/*, {
execArgv: ['--debug=5859']
}*/
);
} catch (err) { } catch (err) {
throw 'Failed to fork channel! (' + err + ')'; throw 'Failed to fork channel! (' + err + ')';
} }