fixed debug view and ragdoll start positioning

This commit is contained in:
Jeena 2015-03-16 01:50:41 +01:00
parent b6d979fe7c
commit 16826b174a
12 changed files with 135 additions and 73 deletions

View file

@ -102,10 +102,10 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
//this.createSensor();
this.limbs = {};
this.addHead();
this.addLimb(
"upperLeftLeg",
this.body,
@ -137,7 +137,6 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
this.addLimb(
"upperLeftArm",
this.body,
@ -165,6 +164,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
0,
options.limbs.upperRightArm.height / 2
);
}
RagDoll.prototype = Object.create(Parent.prototype);
@ -185,6 +185,8 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
var bodyDef = Parent.prototype.getBodyDef.call(this);
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bodyDef.position.y -= this.options.height / 2 / Settings.RATIO; // position it on top of ground
return bodyDef;
};
@ -235,7 +237,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
Assert.number(this.options.limbs.head.width);
var x = this.options.x + this.options.limbs.head.x,
y = this.options.y + this.options.limbs.head.y;
y = this.options.y + this.options.limbs.head.y - this.options.height / 2; // position it on top of ground;
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
@ -286,7 +288,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
Assert.number(this.options.limbs[name].width, this.options.limbs[name].height);
var x = this.options.x + this.options.limbs[name].x,
y = this.options.y + this.options.limbs[name].y;
y = this.options.y + this.options.limbs[name].y - this.options.height / 2; // position it on top of ground;;
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;

View file

@ -51,7 +51,6 @@ function (Parent, Box2D, Settings, Assert) {
};
Skateboard.prototype.addWheel = function(x, y) {
Assert.number(x, y);
var bodyDef = new Box2D.Dynamics.b2BodyDef();
@ -71,15 +70,20 @@ function (Parent, Box2D, Settings, Assert) {
fixtureDef.density = density;
fixtureDef.shape = wheelShape;
fixtureDef.isSensor = false;
fixtureDef.friction = 0;
var wheelBody = this.body.GetWorld().CreateBody(bodyDef);
wheelBody.CreateFixture(fixtureDef);
var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
revoluteJointDef.enableMotor = false;
//var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
var revoluteJointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
//revoluteJointDef.enableMotor = false;
revoluteJointDef.Initialize(this.body, wheelBody, wheelBody.GetWorldCenter());
this.body.GetWorld().CreateJoint(revoluteJointDef);
var j = this.body.GetWorld().CreateJoint(revoluteJointDef);
// FIXME this means, that we will have bodies in the world, which must not be
// updated (wheels) because they are always connected to a body which will be updated.