Commit 28b0350e by 李楚霏

调整

parent 798d5fc9
...@@ -2339,7 +2339,7 @@ ...@@ -2339,7 +2339,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 10000, "_density": 170,
"_sensor": false, "_sensor": false,
"_friction": 1, "_friction": 1,
"_restitution": 0.1, "_restitution": 0.1,
...@@ -2364,8 +2364,6 @@ ...@@ -2364,8 +2364,6 @@
"__id__": 40 "__id__": 40
}, },
"_enabled": true, "_enabled": true,
"label": null,
"text": "hello",
"_id": "a7LuEyw79BAYxThj2PaotL" "_id": "a7LuEyw79BAYxThj2PaotL"
}, },
{ {
...@@ -2742,7 +2740,7 @@ ...@@ -2742,7 +2740,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 450, "_density": 250,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -2949,7 +2947,7 @@ ...@@ -2949,7 +2947,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 400, "_density": 220,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -3156,7 +3154,7 @@ ...@@ -3156,7 +3154,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 350, "_density": 200,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -3363,7 +3361,7 @@ ...@@ -3363,7 +3361,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 300, "_density": 120,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -3570,7 +3568,7 @@ ...@@ -3570,7 +3568,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 250, "_density": 110,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -3777,7 +3775,7 @@ ...@@ -3777,7 +3775,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 200, "_density": 100,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -3984,7 +3982,7 @@ ...@@ -3984,7 +3982,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 150, "_density": 90,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -4191,7 +4189,7 @@ ...@@ -4191,7 +4189,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 100, "_density": 80,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -4398,7 +4396,7 @@ ...@@ -4398,7 +4396,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 100, "_density": 70,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -4605,7 +4603,7 @@ ...@@ -4605,7 +4603,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 100, "_density": 60,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -4812,7 +4810,7 @@ ...@@ -4812,7 +4810,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 100, "_density": 50,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -5019,7 +5017,7 @@ ...@@ -5019,7 +5017,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 100, "_density": 40,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -5226,7 +5224,7 @@ ...@@ -5226,7 +5224,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 100, "_density": 30,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -5433,7 +5431,7 @@ ...@@ -5433,7 +5431,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 100, "_density": 20,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -5574,8 +5572,8 @@ ...@@ -5574,8 +5572,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
188.852, 188.143,
-236.019, -217.587,
0, 0,
0, 0,
0, 0,
...@@ -5640,7 +5638,7 @@ ...@@ -5640,7 +5638,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 100, "_density": 20,
"_sensor": false, "_sensor": false,
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
...@@ -5648,7 +5646,7 @@ ...@@ -5648,7 +5646,7 @@
"_offset": { "_offset": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": 0, "x": 0,
"y": -25 "y": 0
}, },
"_size": { "_size": {
"__type__": "cc.Size", "__type__": "cc.Size",
...@@ -5789,8 +5787,8 @@ ...@@ -5789,8 +5787,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
179.03, 188.246,
-465.162, -366.622,
0, 0,
0, 0,
0, 0,
...@@ -6105,7 +6103,7 @@ ...@@ -6105,7 +6103,7 @@
}, },
"_enabled": true, "_enabled": true,
"tag": 0, "tag": 0,
"_density": 2, "_density": 4,
"_sensor": false, "_sensor": false,
"_friction": 1, "_friction": 1,
"_restitution": 0, "_restitution": 0,
......
...@@ -10,39 +10,40 @@ const {ccclass, property} = cc._decorator; ...@@ -10,39 +10,40 @@ const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
startPoint: any; startPoint: any;
rigidBody: any; rigidBody: any;
tween: any; tween: any;
startCollision: boolean = false;
points: any = [];
nodePos: cc.Vec2;
dir: cc.Vec3;
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
onPreSolve(contact, selfCollider, otherCollider) { onPreSolve(contact, selfCollider, otherCollider) {
if (otherCollider.node.name.includes('disk')) { if (otherCollider.node.name.includes('disk')) {
this.moveEnd(); // this.moveEnd();
this.startCollision = true;
this.scheduleOnce(()=>{ this.scheduleOnce(()=>{
console.error('1');
this.rigidBody.type = cc.RigidBodyType.Dynamic; this.rigidBody.type = cc.RigidBodyType.Dynamic;
otherCollider.node.getComponent(cc.RigidBody).type = cc.RigidBodyType.Kinematic; otherCollider.node.getComponent(cc.RigidBody).type = cc.RigidBodyType.Kinematic;
const joint = this.node.getComponent(cc.WeldJoint); let joint = this.node.addComponent(cc.WeldJoint);
joint.enabled =true; joint.connectedAnchor = cc.v2(-51.8, 0.4);
joint.connectedBody = otherCollider.node; joint.connectedBody = otherCollider.node.getComponent(cc.RigidBody);
}) }, 0);
// joint.anchor = cc.v2(-51.7, -1.1); // joint.anchor = cc.v2(-51.7, -1.1);
} }
} }
onPostSolve(contact, selfCollider, otherCollider) { onPostSolve(contact, selfCollider, otherCollider) {
this.scheduleOnce(()=>{ // this.schedule(()=>{
this.rigidBody.type = cc.RigidBodyType.Kinematic; // this.rigidBody.type = cc.RigidBodyType.Kinematic;
otherCollider.node.getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic; // otherCollider.node.getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
}) // },0);
} }
onLoad () { onLoad () {
this.dir = cc.v3(this.node.position.x, this.node.position.y, 0);
this.rigidBody = this.node.getComponent(cc.RigidBody); this.rigidBody = this.node.getComponent(cc.RigidBody);
this.rigidBody.type = cc.RigidBodyType.Kinematic; this.rigidBody.type = cc.RigidBodyType.Kinematic;
this.initEvent(); this.initEvent();
...@@ -56,25 +57,16 @@ export default class NewClass extends cc.Component { ...@@ -56,25 +57,16 @@ export default class NewClass extends cc.Component {
} }
_touchStartEvent(event: cc.Event.EventTouch) { _touchStartEvent(event: cc.Event.EventTouch) {
this.startPoint = event.getPreviousLocation(); // this.startPoint = event.getStartLocation();
} }
_touchMoveEvent(event: cc.Event.EventTouch) { _touchMoveEvent(event: cc.Event.EventTouch) {
// this.points.push(event.getLocation()); var touches = event.getTouches();
// if (this.points.length > 20) { let oldPos = this.node.parent.convertToNodeSpaceAR(touches[0].getStartLocation());
// this.points.shift(); let newPos = this.node.parent.convertToNodeSpaceAR(touches[0].getLocation());
// } // let subPos = oldPos.sub(newPos);
// const averagePoint = new cc.Vec2(0, 0); // let dir = cc.v3(this.nodePos.x - subPos.x, this.nodePos.y - subPos.y, 0);
// this.points.forEach((point) => { this.dir = cc.v3(newPos.x, newPos.y, 0);
// averagePoint.x += point.x; // this.move(dir);
// averagePoint.y += point.y;
// })
// averagePoint.multiplyScalar(1 / this.points.length);
// const delta = new cc.Vec2(event.getLocation().x - averagePoint.x, event.getLocation().y - averagePoint.y);
// let dir = delta;
let dir = cc.v2(event.getLocation().x - this.startPoint.x, event.getLocation().y - this.startPoint.y);
// clientEvent.dispatchEvent('move', dir);
this.move(dir);
} }
_touchEndEvent(event: cc.Event.EventTouch) { _touchEndEvent(event: cc.Event.EventTouch) {
...@@ -88,25 +80,23 @@ export default class NewClass extends cc.Component { ...@@ -88,25 +80,23 @@ export default class NewClass extends cc.Component {
} }
move(dir) { move(dir) {
// this.node.position = dir;
this.tween = cc.tween(this.node)
.to(0.7, {position: dir})
.start()
// this.rigidBody.awake = true;
// cc.director.getPhysicsManager().enabled = false;
} }
moveEnd() { moveEnd() {
if (this.tween) {
this.tween.stop();
}
// cc.director.getPhysicsManager().enabled = true;
} }
start () { start () {
} }
// update (dt) { update (dt) {
// } const oldPos = cc.v3 (this.node.position.x, this.node.position.y, 0);
let targetPos = this.dir.clone();
let subPos = targetPos.sub(oldPos);
let distance = subPos.mag();
if (distance > 100) {
targetPos = oldPos.clone().add(targetPos.sub(oldPos.clone()).normalizeSelf().mul(100));
}
this.node.position = this.node.position.clone().lerp(targetPos, 4*dt);
}
} }
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