mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
only adds lastMovedBy when there was no damage - fixes #99
This commit is contained in:
parent
e370adf746
commit
0edde06d67
8 changed files with 403 additions and 21 deletions
|
|
@ -35,9 +35,9 @@ function(Parent, Nc, Parser, Settings) {
|
|||
};
|
||||
|
||||
PlayerController.prototype.handActionRequest = function(options) {
|
||||
options.x = parseFloat(options.x) || 0;
|
||||
options.y = parseFloat(options.y) || 0;
|
||||
options.av = parseFloat(options.av) || 0;
|
||||
options.x = parseFloat(options.x) || 0.0;
|
||||
options.y = parseFloat(options.y) || 0.0;
|
||||
options.av = parseFloat(options.av) || 0.0;
|
||||
if (options) this.player.handActionRequest(options);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,17 @@ function (Parent, Layer, Settings, Nc) {
|
|||
};
|
||||
|
||||
RubeDoll.prototype.render = function() {
|
||||
Parent.prototype.render.call(this);
|
||||
//Parent.prototype.render.call(this);
|
||||
|
||||
Nc.trigger(Nc.ns.client.view.mesh.update,
|
||||
this.layerId,
|
||||
this.mesh,
|
||||
{
|
||||
x: this.body.GetPosition().x * Settings.RATIO,
|
||||
y: this.body.GetPosition().y * Settings.RATIO,
|
||||
rotation: this.body.GetAngle()
|
||||
}
|
||||
);
|
||||
|
||||
if(this.limbs) {
|
||||
for(var name in this.limbMeshes) {
|
||||
|
|
@ -187,6 +197,10 @@ function (Parent, Layer, Settings, Nc) {
|
|||
};
|
||||
|
||||
RubeDoll.prototype.flip = function(direction) {
|
||||
return;
|
||||
|
||||
|
||||
|
||||
Parent.prototype.flip.call(this, direction);
|
||||
|
||||
// flipping depth of right body side arm/leg images with left
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ function () {
|
|||
"height": "9",
|
||||
|
||||
"type": "rubedoll",
|
||||
"grabAngle": "0.1",
|
||||
"grabAngle": "0.001", // seems to be a bug, that 0 does not work!
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ function () {
|
|||
BOX2D_WORLD_AABB_SIZE: 3000,
|
||||
BOX2D_ALLOW_SLEEP: true,
|
||||
BOX2D_GRAVITY: 26,
|
||||
BOX2D_VELOCITY_ITERATIONS: 200,
|
||||
BOX2D_POSITION_ITERATIONS: 100,
|
||||
BOX2D_VELOCITY_ITERATIONS: 20,
|
||||
BOX2D_POSITION_ITERATIONS: 10, // 200/100 created problems (awful teleporting when repositioning joints)
|
||||
BOX2D_TIME_STEP: 1 / 60,
|
||||
|
||||
// PATHS
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ function (Parent, Box2D, Options, Settings, Exception, Nc, Assert) {
|
|||
);
|
||||
this.body.SetPosition(position);
|
||||
this.flip(direction);
|
||||
this.body.SetAngle((this.options.grabAngle || 0) * direction);
|
||||
this.body.SetAngle((this.options.grabAngle || 0.0) * direction);
|
||||
};
|
||||
|
||||
Item.prototype.getGrabPoint = function() {
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
|
|||
chestPosition.y + this.options.limbs.head.y / Settings.RATIO
|
||||
);
|
||||
this.limbs.head.SetPosition(position);
|
||||
this.limbs.head.SetAngle((this.options.grabAngle || 0) * direction);
|
||||
this.limbs.head.SetAngle((this.options.grabAngle || 0.0) * direction);
|
||||
};
|
||||
|
||||
RagDoll.prototype.throw = function(options, carrierVelocity) {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ define([
|
|||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Assert",
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Matrix",
|
||||
"json!Game/Asset/RubeDoll.json" // using requirejs json loader plugin
|
||||
],
|
||||
|
||||
function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
||||
function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, Matrix, RubeDollJson) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
@ -66,11 +67,21 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
|||
|
||||
this.joints = scene.joints;
|
||||
|
||||
var count = 0;
|
||||
for (var i in this.joints) {
|
||||
this.limits[i] = {
|
||||
lower: this.joints[i].GetLowerLimit(),
|
||||
upper: this.joints[i].GetUpperLimit(),
|
||||
};
|
||||
|
||||
this.joints[i].EnableLimit(false);
|
||||
|
||||
if(count < 4 && this.joints[i] instanceof Box2D.Dynamics.Joints.b2RevoluteJoint) {
|
||||
console.log(i);
|
||||
} else {
|
||||
body.GetWorld().DestroyJoint(this.joints[i]);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -82,7 +93,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
|||
|
||||
RubeDoll.prototype.flip = function(direction) {
|
||||
|
||||
Parent.prototype.flip.call(this, direction);
|
||||
//Parent.prototype.flip.call(this, direction);
|
||||
/*
|
||||
|
||||
for (var i in this.joints) {
|
||||
|
|
@ -109,24 +120,45 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
|||
};
|
||||
|
||||
RubeDoll.prototype.reposition = function(handPosition, direction) {
|
||||
console.log('repo');
|
||||
|
||||
var oldPosition = this.getPosition();
|
||||
|
||||
var oldAngle = this.body.GetAngle();
|
||||
Parent.prototype.reposition.call(this, handPosition, direction);
|
||||
var differenceAngle = oldAngle - this.body.GetAngle();
|
||||
|
||||
//this.body.SetType(Box2D.Dynamics.b2Body.b2_staticBody)
|
||||
//this.body.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0));
|
||||
|
||||
var newPosition = this.getPosition();
|
||||
var b2Math = Box2D.Common.Math.b2Math;
|
||||
var offset = b2Math.SubtractVV(newPosition, oldPosition);
|
||||
var offset = Box2D.Common.Math.b2Math.SubtractVV(this.getPosition(), oldPosition);
|
||||
var grabAngle = (this.options.grabAngle || 0.001);
|
||||
|
||||
for(var limb in this.limbs) {
|
||||
var position = this.limbs[limb].GetPosition().Copy();
|
||||
for(var key in this.limbs) {
|
||||
var limb = this.limbs[key];
|
||||
|
||||
// Setting position offset first (floor to hand)
|
||||
var position = limb.GetPosition().Copy();
|
||||
position.Add(offset);
|
||||
this.limbs[limb].SetPosition(position);
|
||||
//this.limbs[limb].SetType(Box2D.Dynamics.b2Body.b2_staticBody)
|
||||
}
|
||||
limb.SetPosition(position);
|
||||
|
||||
// grabing local point to "rotate" around (x, y position transform only)
|
||||
var localPoint = this.body.GetLocalPoint(limb.GetPosition().Copy());
|
||||
|
||||
// create rotation matrix from chest rotation difference
|
||||
var mat = Box2D.Common.Math.b2Mat22.FromAngle(differenceAngle);
|
||||
|
||||
// matrix multiplication with local limb position
|
||||
position = Box2D.Common.Math.b2Math.MulTMV(mat, localPoint);
|
||||
|
||||
// translating back to global position
|
||||
var globalPoint = this.body.GetWorldPoint(position);
|
||||
limb.SetPosition(globalPoint);
|
||||
|
||||
// relative limb rotating by chest rotation difference
|
||||
limb.SetAngle(limb.GetAngle() - differenceAngle);
|
||||
|
||||
//limb.SetType(Box2D.Dynamics.b2Body.b2_staticBody);
|
||||
//limb.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0));
|
||||
}
|
||||
};
|
||||
|
||||
RubeDoll.prototype.setVelocities = function(options) {
|
||||
|
|
@ -152,6 +184,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
|||
|
||||
Parent.prototype.setUpdateData.call(this, update);
|
||||
|
||||
/*
|
||||
for(var name in update.limbs) {
|
||||
Assert.number(update.limbs[name].p.x, update.limbs[name].p.y);
|
||||
Assert.number(update.limbs[name].a);
|
||||
|
|
@ -164,6 +197,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
|||
this.limbs[name].SetLinearVelocity(update.limbs[name].lv);
|
||||
this.limbs[name].SetAngularVelocity(update.limbs[name].av);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
RubeDoll.prototype.destroy = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue