Commit b8bf8c22 by 李楚霏

修改齿轮不重合的问题

parent ef8e5f7f
......@@ -18,8 +18,9 @@ export default class NewClass extends cc.Component {
collider: cc.PhysicsPolygonCollider;
startPoint: cc.Vec2;
tween: any;
points:cc.Vec2;
points:cc.Vec3;
startCollision: boolean =false;
relativeVelocity: any;
// LIFE-CYCLE CALLBACKS:
onBeginContact(contact, selfCollider, otherCollider) {
......@@ -30,14 +31,23 @@ export default class NewClass extends cc.Component {
}
onPreSolve(contact, selfCollider, otherCollider) {
if (otherCollider.node.name.includes('staticGear')) {
this.startCollision = true;
this.points = otherCollider.node.getComponent(cc.RigidBody).getWorldCenter();
this.rigidBody.angularVelocity = - otherCollider.node.getComponent(cc.RigidBody).angularVelocity;
}
// this.node.position = otherCollider.node.position;
var worldManifold = contact.getWorldManifold();
var vel1 = selfCollider.node.getComponent(cc.RigidBody).getLinearVelocityFromWorldPoint(worldManifold.points[0]);
var vel2 = otherCollider.node.getComponent(cc.RigidBody).getLinearVelocityFromWorldPoint(worldManifold.points[0]);
this.relativeVelocity = vel1.sub(vel2);
this.scheduleOnce(()=>{
this.rigidBody.linearVelocity = this.relativeVelocity;
setTimeout(() => {
this.rigidBody.linearVelocity = cc.v2(0,0);
}, 300);
}, 0);
}
}
onPostSolve(contact, selfCollider, otherCollider) {
// this.rigidBody.angularVelocity = 0;
this.rigidBody.angularVelocity = 0;
// this.startCollision = false;
}
......@@ -102,15 +112,6 @@ export default class NewClass extends cc.Component {
}
update (dt) {
if (!this.startCollision)
return;
const point = this.rigidBody.getWorldCenter();
let subPos = point.sub(this.points);
let distance = subPos.mag();
if(distance <= this.node.width) {
// this.node.position = this.node.position.clone().add(cc.v3(this.points.x, this.points.y ,0));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment