Commit 28b0350e by 李楚霏

调整

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