Commit 166ff661 by 李楚霏

调整

parent 28b0350e
......@@ -18,23 +18,18 @@ export default class NewClass extends cc.Component {
collider: cc.PhysicsPolygonCollider;
startPoint: cc.Vec2;
tween: any;
points: cc.Vec2;
// LIFE-CYCLE CALLBACKS:
onPreSolve(contact, selfCollider, otherCollider) {
// console.error(otherCollider.node.name);
// if (otherCollider && otherCollider.node.getComponent(cc.MotorJoint)) {
// // this.rigidBody.awake = false;
// console.error(selfCollider.name);
// otherCollider.node.addComponent(cc.MotorJoint);
// const motor = otherCollider.node.getComponent(cc.MotorJoint);
// motor.connectedBody = this.node;
// motor.maxTorque = -200;
// }
// const motorJoint =this.node.getComponent(cc.MotorJoint);
// motorJoint.connectedBody = otherCollider.node;
// console.error(motorJoint.connectedBody.name);
// console.error(contact);
const worldManifold = contact.getWorldManifold();
this.points = worldManifold.normal;
if (otherCollider.node.name.includes('staticGear')) {
this.rigidBody.angularVelocity = - otherCollider.node.getComponent(cc.RigidBody).angularVelocity;
this.scheduleOnce(() => {
this.node.position = cc.v3(this.points.x, this.points.y, 0);
this.rigidBody.angularVelocity = - otherCollider.node.getComponent(cc.RigidBody).angularVelocity;
},0);
}
}
......@@ -48,8 +43,6 @@ export default class NewClass extends cc.Component {
}
onEnable() {
clientEvent.on('move', this.move, this);
clientEvent.on('moveEnd', this.moveEnd, this);
}
initEvent() {
......@@ -92,17 +85,11 @@ export default class NewClass extends cc.Component {
}
move(dir) {
console.error('move');
this.tween = cc.tween(this.node)
.to(1, {position: dir})
.start()
// this.node.position = dir;
this.node.position = dir;
// this.rigidBody.awake = true;
cc.director.getPhysicsManager().enabled = false;
}
moveEnd() {
console.error('moveEnd');
this.tween.stop();
cc.director.getPhysicsManager().enabled = true;
}
......
......@@ -61,7 +61,6 @@ export default class NewClass extends cc.Component {
}
_touchMoveEvent(event: cc.Event.EventTouch) {
var touches = event.getTouches();
let oldPos = this.node.parent.convertToNodeSpaceAR(touches[0].getStartLocation());
let newPos = this.node.parent.convertToNodeSpaceAR(touches[0].getLocation());
// let subPos = oldPos.sub(newPos);
// let dir = cc.v3(this.nodePos.x - subPos.x, this.nodePos.y - subPos.y, 0);
......
......@@ -32,7 +32,7 @@ export default class NewClass extends cc.Component {
// const motorJoint =this.node.getComponent(cc.MotorJoint);
// motorJoint.connectedBody = otherCollider.node;
// console.error(motorJoint.connectedBody.name);
this.rigidBody.linearVelocity = cc.v2(0, otherCollider.node.getComponent(cc.RigidBody).angularVelocity * 3);
this.rigidBody.linearVelocity = cc.v2(0, -otherCollider.node.getComponent(cc.RigidBody).angularVelocity * 3);
}
onPostSolve(contact, selfCollider, otherCollider) {
this.rigidBody.linearVelocity = cc.v2(0, 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