Commit 166ff661 by 李楚霏

调整

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