Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Birb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gadig
Birb
Commits
8c74d0fa
Commit
8c74d0fa
authored
Mar 07, 2017
by
Tanner Grehawick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor CollisionState
parent
82d354a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
10 deletions
+42
-10
Assets/Scripts/Player/CollisionState.cs
Assets/Scripts/Player/CollisionState.cs
+40
-8
Assets/Scripts/Player/CollisionState.cs.meta
Assets/Scripts/Player/CollisionState.cs.meta
+2
-2
No files found.
Assets/Scripts/Player/CollisionState.cs
View file @
8c74d0fa
...
...
@@ -23,34 +23,66 @@ public class CollisionState : MonoBehaviour {
void
FixedUpdate
()
{
enemyHit
=
null
;
onGround
=
Physics2D
.
OverlapCircle
(
body
.
position
+
bottomPosition
,
collisionRadius
,
collisionLayer
);
//
onGround = Physics2D.OverlapCircle(body.position + bottomPosition, collisionRadius, collisionLayer);
onWallLeft
=
Physics2D
.
OverlapCircle
(
body
.
position
+
leftPosition
,
collisionRadius
,
collisionLayer
);
onWallRight
=
Physics2D
.
OverlapCircle
(
body
.
position
+
rightPosition
,
collisionRadius
,
collisionLayer
);
onWall
=
onWallRight
||
onWallLeft
;
//
onWallLeft = Physics2D.OverlapCircle(body.position + leftPosition, collisionRadius, collisionLayer);
//
onWallRight = Physics2D.OverlapCircle(body.position + rightPosition, collisionRadius, collisionLayer);
//
onWall = onWallRight || onWallLeft;
enemyHit
=
Physics2D
.
OverlapCircle
(
body
.
position
+
bottomPosition
,
collisionRadius
,
enemyLayer
);
}
void
OnDrawGizmos
()
{
void
OnDrawGizmos
Selected
()
{
Gizmos
.
color
=
Color
.
red
;
Vector2
pos
=
bottomPosition
;
pos
.
x
+=
transform
.
position
.
x
;
pos
.
y
+=
transform
.
position
.
y
;
Gizmos
.
DrawSphere
(
pos
,
collisionRadius
);
Gizmos
.
Draw
Wire
Sphere
(
pos
,
collisionRadius
);
pos
=
rightPosition
;
pos
.
x
+=
transform
.
position
.
x
;
pos
.
y
+=
transform
.
position
.
y
;
Gizmos
.
DrawSphere
(
pos
,
collisionRadius
);
Gizmos
.
Draw
Wire
Sphere
(
pos
,
collisionRadius
);
pos
=
leftPosition
;
pos
.
x
+=
transform
.
position
.
x
;
pos
.
y
+=
transform
.
position
.
y
;
Gizmos
.
DrawSphere
(
pos
,
collisionRadius
);
Gizmos
.
DrawWireSphere
(
pos
,
collisionRadius
);
}
void
OnCollisionStay2D
(
Collision2D
collision
)
{
onGround
=
false
;
onWallLeft
=
false
;
onWallRight
=
false
;
foreach
(
ContactPoint2D
contact
in
collision
.
contacts
)
{
Color
color
=
Color
.
white
;
Vector2
normal
=
contact
.
normal
;
if
(
normal
==
Vector2
.
right
)
{
color
=
Color
.
red
;
onWallLeft
=
true
;
}
if
(
normal
==
-
Vector2
.
right
)
{
color
=
Color
.
green
;
onWallRight
=
true
;
}
if
(
normal
==
Vector2
.
up
)
{
color
=
Color
.
blue
;
onGround
=
true
;
}
onWall
=
onWallLeft
||
onWallRight
;
Debug
.
DrawRay
(
contact
.
point
,
contact
.
normal
,
color
);
}
}
void
OnCollisionExit2D
()
{
onGround
=
false
;
onWallLeft
=
false
;
onWallRight
=
false
;
onWall
=
false
;
}
}
Assets/Scripts/Player/CollisionState.cs.meta
100644 → 100755
View file @
8c74d0fa
fileFormatVersion: 2
guid: c5db22d5529dd524b9174371b8f9af7a
timeCreated: 148
6076722
timeCreated: 148
8938661
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
executionOrder:
-10
0
icon: {instanceID: 0}
userData:
assetBundleName:
...
...
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