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
4 years ago
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整
parent
166ff661
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
rescureMen/assets/scene/test.fire
+0
-0
rescureMen/assets/script/gear.ts
+21
-8
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 {
...
@@ -18,23 +18,27 @@ 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
;
points
:
cc
.
Vec2
;
startCollision
:
boolean
=
false
;
// LIFE-CYCLE CALLBACKS:
// LIFE-CYCLE CALLBACKS:
onBeginContact
(
contact
,
selfCollider
,
otherCollider
)
{
}
onEndContact
(
contact
,
selfCollider
,
otherCollider
)
{
}
onPreSolve
(
contact
,
selfCollider
,
otherCollider
)
{
onPreSolve
(
contact
,
selfCollider
,
otherCollider
)
{
// console.error(contact);
const
worldManifold
=
contact
.
getWorldManifold
();
this
.
points
=
worldManifold
.
normal
;
if
(
otherCollider
.
node
.
name
.
includes
(
'staticGear'
))
{
if
(
otherCollider
.
node
.
name
.
includes
(
'staticGear'
))
{
this
.
s
cheduleOnce
(()
=>
{
this
.
s
tartCollision
=
true
;
this
.
node
.
position
=
cc
.
v3
(
this
.
points
.
x
,
this
.
points
.
y
,
0
);
this
.
points
=
otherCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
getWorldCenter
(
);
this
.
rigidBody
.
angularVelocity
=
-
otherCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
angularVelocity
;
this
.
rigidBody
.
angularVelocity
=
-
otherCollider
.
node
.
getComponent
(
cc
.
RigidBody
).
angularVelocity
;
},
0
);
}
}
}
}
onPostSolve
(
contact
,
selfCollider
,
otherCollider
)
{
onPostSolve
(
contact
,
selfCollider
,
otherCollider
)
{
this
.
rigidBody
.
angularVelocity
=
0
;
// this.rigidBody.angularVelocity = 0;
// this.startCollision = false;
}
}
onLoad
()
{
onLoad
()
{
...
@@ -98,6 +102,15 @@ export default class NewClass extends cc.Component {
...
@@ -98,6 +102,15 @@ export default class NewClass extends cc.Component {
}
}
update
(
dt
)
{
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));
}
}
}
}
}
This diff is collapsed.
Click to expand it.
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