mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed jumping while falling. fixes #70
This commit is contained in:
parent
20ccb4c8c8
commit
450d1d6473
1 changed files with 34 additions and 3 deletions
|
|
@ -25,6 +25,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
this.moveDirection = 0;
|
||||
this.lookDirection = 0;
|
||||
this.legs;
|
||||
this.footSensor;
|
||||
this.actionState = null;
|
||||
this.lookAtXY = { x:0, y:0 };
|
||||
this.reachableItems = {
|
||||
|
|
@ -104,7 +105,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
onCollisionChange: this.onFootSensorDetection.bind(this)
|
||||
}
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
this.footSensor = this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var grabSensorLeftShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
grabSensorLeftShape.SetAsOrientedBox(
|
||||
|
|
@ -365,11 +366,41 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
|
||||
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {
|
||||
|
||||
var self = this;
|
||||
|
||||
var hasJumpStartVelocity = this.body.GetLinearVelocity().y < -Settings.JUMP_SPEED;
|
||||
|
||||
if(isColliding && !hasJumpStartVelocity) {
|
||||
if(isColliding) {
|
||||
if(!hasJumpStartVelocity) {
|
||||
this.setStanding(true);
|
||||
}
|
||||
} else {
|
||||
|
||||
var contactCount = 0;
|
||||
|
||||
var edge = self.body.GetContactList();
|
||||
while (edge) {
|
||||
var contact = edge.contact;
|
||||
if(!contact.IsTouching()) {
|
||||
edge = edge.next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(contact.GetFixtureA() === self.footSensor) {
|
||||
contactCount++;
|
||||
}
|
||||
|
||||
if(contact.GetFixtureB() === self.footSensor) {
|
||||
contactCount++;
|
||||
}
|
||||
|
||||
edge = edge.next;
|
||||
}
|
||||
|
||||
if (contactCount === 0) {
|
||||
self.setStanding(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Doll.prototype.onImpact = function(isColliding, fixture) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue