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
ef8e5f7f
authored
Jul 08, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整
parent
166ff661
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
9 deletions
+22
-9
rescureMen/assets/scene/test.fire
+0
-0
rescureMen/assets/script/gear.ts
+22
-9
No files found.
rescureMen/assets/scene/test.fire
View file @
ef8e5f7f
This diff is collapsed.
Click to expand it.
rescureMen/assets/script/gear.ts
View file @
ef8e5f7f
...
...
@@ -18,23 +18,27 @@ export default class NewClass extends cc.Component {
collider
:
cc
.
PhysicsPolygonCollider
;
startPoint
:
cc
.
Vec2
;
tween
:
any
;
points
:
cc
.
Vec2
;
points
:
cc
.
Vec2
;
startCollision
:
boolean
=
false
;
// LIFE-CYCLE CALLBACKS:
onBeginContact
(
contact
,
selfCollider
,
otherCollider
)
{
}
onEndContact
(
contact
,
selfCollider
,
otherCollider
)
{
}
onPreSolve
(
contact
,
selfCollider
,
otherCollider
)
{
// console.error(contact);
const
worldManifold
=
contact
.
getWorldManifold
();
this
.
points
=
worldManifold
.
normal
;
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
;
},
0
);
this
.
startCollision
=
true
;
this
.
points
=
otherCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
getWorldCenter
();
this
.
rigidBody
.
angularVelocity
=
-
otherCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
angularVelocity
;
}
}
onPostSolve
(
contact
,
selfCollider
,
otherCollider
)
{
this
.
rigidBody
.
angularVelocity
=
0
;
// this.rigidBody.angularVelocity = 0;
// this.startCollision = false;
}
onLoad
()
{
...
...
@@ -98,6 +102,15 @@ 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