mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 08:42:43 +08:00
fixed physics system (#2984)
* should reset physics contact * fixed physics debug draw * fixed revolute joint limit
This commit is contained in:
@@ -217,6 +217,10 @@ PhysicsContact.prototype.init = function (b2contact) {
|
||||
};
|
||||
|
||||
PhysicsContact.prototype.reset = function () {
|
||||
this.setTangentSpeed(0);
|
||||
this.resetFriction();
|
||||
this.resetRestitution();
|
||||
|
||||
this.colliderA = null;
|
||||
this.colliderB = null;
|
||||
this.disabled = false;
|
||||
|
||||
@@ -537,7 +537,9 @@ var PhysicsManager = cc.Class({
|
||||
cc.game.addPersistRootNode(node);
|
||||
this._debugDrawer = node.addComponent(cc.Graphics);
|
||||
|
||||
this._world.SetDebugDraw(new DebugDraw(this._debugDrawer));
|
||||
let debugDraw = new DebugDraw(this._debugDrawer);
|
||||
debugDraw.SetFlags(this.debugDrawFlags);
|
||||
this._world.SetDebugDraw(debugDraw);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -609,6 +611,11 @@ cc.js.getset(PhysicsManager.prototype, 'debugDrawFlags',
|
||||
}
|
||||
|
||||
this._debugDrawFlags = value;
|
||||
|
||||
if (value) {
|
||||
this._checkDebugDrawValid();
|
||||
this._world.m_debugDraw.SetFlags(value);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -198,14 +198,28 @@ var RevoluteJoint = cc.Class({
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* #!en
|
||||
* Set the max and min limit angle.
|
||||
* #!zh
|
||||
* 设置关节的角度最大和最小角度。
|
||||
* @param {Number} lower
|
||||
* @param {Number} upper
|
||||
*/
|
||||
setLimits (lower, upper) {
|
||||
if (this._joint) {
|
||||
return this._joint.SetLimits(lower * ANGLE_TO_PHYSICS_ANGLE, upper * ANGLE_TO_PHYSICS_ANGLE);
|
||||
}
|
||||
},
|
||||
|
||||
_createJointDef: function () {
|
||||
var def = new b2.RevoluteJointDef();
|
||||
def.localAnchorA = new b2.Vec2(this.anchor.x/PTM_RATIO, this.anchor.y/PTM_RATIO);
|
||||
def.localAnchorB = new b2.Vec2(this.connectedAnchor.x/PTM_RATIO, this.connectedAnchor.y/PTM_RATIO);
|
||||
|
||||
// cocos degree 0 is to right, and box2d degree 0 is to up.
|
||||
def.lowerAngle = (this.upperAngle + 90) * ANGLE_TO_PHYSICS_ANGLE;
|
||||
def.upperAngle = (this.lowerAngle + 90) * ANGLE_TO_PHYSICS_ANGLE;
|
||||
def.lowerAngle = this.upperAngle* ANGLE_TO_PHYSICS_ANGLE;
|
||||
def.upperAngle = this.lowerAngle* ANGLE_TO_PHYSICS_ANGLE;
|
||||
|
||||
def.maxMotorTorque = this.maxMotorTorque;
|
||||
def.motorSpeed = this.motorSpeed * ANGLE_TO_PHYSICS_ANGLE;
|
||||
|
||||
Reference in New Issue
Block a user