Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
天梦-黄聪鑫
/
RescureMenDemo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b8bf8c22
authored
Jul 12, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改齿轮不重合的问题
parent
ef8e5f7f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
rescureMen/assets/script/gear.ts
+15
-14
No files found.
rescureMen/assets/script/gear.ts
View file @
b8bf8c22
...
...
@@ -18,8 +18,9 @@ export default class NewClass extends cc.Component {
collider
:
cc
.
PhysicsPolygonCollider
;
startPoint
:
cc
.
Vec2
;
tween
:
any
;
points
:
cc
.
Vec
2
;
points
:
cc
.
Vec
3
;
startCollision
:
boolean
=
false
;
relativeVelocity
:
any
;
// LIFE-CYCLE CALLBACKS:
onBeginContact
(
contact
,
selfCollider
,
otherCollider
)
{
...
...
@@ -30,14 +31,23 @@ export default class NewClass extends cc.Component {
}
onPreSolve
(
contact
,
selfCollider
,
otherCollider
)
{
if
(
otherCollider
.
node
.
name
.
includes
(
'staticGear'
))
{
this
.
startCollision
=
true
;
this
.
points
=
otherCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
getWorldCenter
();
this
.
rigidBody
.
angularVelocity
=
-
otherCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
angularVelocity
;
}
// this.node.position = otherCollider.node.position;
var
worldManifold
=
contact
.
getWorldManifold
();
var
vel1
=
selfCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
getLinearVelocityFromWorldPoint
(
worldManifold
.
points
[
0
]);
var
vel2
=
otherCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
getLinearVelocityFromWorldPoint
(
worldManifold
.
points
[
0
]);
this
.
relativeVelocity
=
vel1
.
sub
(
vel2
);
this
.
scheduleOnce
(()
=>
{
this
.
rigidBody
.
linearVelocity
=
this
.
relativeVelocity
;
setTimeout
(()
=>
{
this
.
rigidBody
.
linearVelocity
=
cc
.
v2
(
0
,
0
);
},
300
);
},
0
);
}
}
onPostSolve
(
contact
,
selfCollider
,
otherCollider
)
{
//
this.rigidBody.angularVelocity = 0;
this
.
rigidBody
.
angularVelocity
=
0
;
// this.startCollision = false;
}
...
...
@@ -102,15 +112,6 @@ 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));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment