Commit ef8e5f7f by 李楚霏

调整

parent 166ff661
......@@ -18,23 +18,27 @@ export default class NewClass extends cc.Component {
collider: cc.PhysicsPolygonCollider;
startPoint: cc.Vec2;
tween: any;
points: cc.Vec2;
points:cc.Vec2;
startCollision: boolean =false;
// LIFE-CYCLE CALLBACKS:
onBeginContact(contact, selfCollider, otherCollider) {
}
onEndContact(contact, selfCollider, otherCollider) {
}
onPreSolve(contact, selfCollider, otherCollider) {
// console.error(contact);
const worldManifold = contact.getWorldManifold();
this.points = worldManifold.normal;
if (otherCollider.node.name.includes('staticGear')) {
this.scheduleOnce(() => {
this.node.position = cc.v3(this.points.x, this.points.y, 0);
this.rigidBody.angularVelocity = - otherCollider.node.getComponent(cc.RigidBody).angularVelocity;
},0);
this.startCollision = true;
this.points = otherCollider.node.getComponent(cc.RigidBody).getWorldCenter();
this.rigidBody.angularVelocity = - otherCollider.node.getComponent(cc.RigidBody).angularVelocity;
}
}
onPostSolve(contact, selfCollider, otherCollider) {
this.rigidBody.angularVelocity = 0;
// this.rigidBody.angularVelocity = 0;
// this.startCollision = false;
}
onLoad () {
......@@ -98,6 +102,15 @@ 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