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
a76b053a
Commit
a76b053a
authored
Apr 20, 2017
by
Tanner Grehawick
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'character-wallslide-fix'
parents
4f5c0d00
222a2258
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
37 deletions
+42
-37
Assets/Scripts/Player/CollisionState.cs
Assets/Scripts/Player/CollisionState.cs
+41
-36
Assets/Scripts/Player/Walk.cs
Assets/Scripts/Player/Walk.cs
+1
-1
No files found.
Assets/Scripts/Player/CollisionState.cs
View file @
a76b053a
...
...
@@ -7,6 +7,7 @@ public class CollisionState : MonoBehaviour {
public
LayerMask
enemyLayer
;
public
float
skinWidth
=
0
;
public
float
groundCheckDistance
=
0.1f
;
public
float
wallCheckDistance
=
0.1f
;
public
bool
onGround
{
get
;
private
set
;
}
public
bool
onWallLeft
{
get
;
private
set
;
}
...
...
@@ -37,46 +38,50 @@ public class CollisionState : MonoBehaviour {
void
FixedUpdate
()
{
// TODO: enemy hit stuff
RaycastHit2D
hit
;
onGround
=
CheckCollision
(
Vector2
.
down
,
groundCheckDistance
);
onWallLeft
=
CheckCollision
(
Vector2
.
left
,
wallCheckDistance
);
onWallRight
=
CheckCollision
(
Vector2
.
right
,
wallCheckDistance
);
}
RaycastHit2D
hit
=
Physics2D
.
CircleCast
(
circle
.
bounds
.
center
,
// center
circle
.
radius
-
skinWidth
,
// radius
Vector2
.
down
,
// direction
groundCheckDistance
,
// distance
collisionLayer
// layermask
);
onGround
=
hit
.
collider
!=
null
;
bool
CheckCollision
(
Vector2
direction
,
float
range
)
{
return
Physics2D
.
CircleCast
(
circle
.
bounds
.
center
,
// center
circle
.
radius
-
skinWidth
,
// radius
direction
,
// direction
range
,
// distance
collisionLayer
// layermask
).
collider
!=
null
;
}
float
lastFixedTime
;
void
OnCollisionStay2D
(
Collision2D
collision
)
{
if
(
Time
.
fixedTime
!=
lastFixedTime
)
{
// only reset flags at the start of each frame
// (OnCollisionStay2D is called once for every collider this body is in contact with)
onWallLeft
=
false
;
onWallRight
=
false
;
lastFixedTime
=
Time
.
fixedTime
;
}
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
;
}
Debug
.
DrawRay
(
contact
.
point
,
contact
.
normal
,
color
);
}
}
//
void OnCollisionStay2D(Collision2D collision) {
//
if (Time.fixedTime != lastFixedTime) {
//
// only reset flags at the start of each frame
//
// (OnCollisionStay2D is called once for every collider this body is in contact with)
//
onWallLeft = false;
//
onWallRight = false;
//
lastFixedTime = Time.fixedTime;
//
}
//
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;
//
}
//
Debug.DrawRay(contact.point, contact.normal, color);
//
}
//
}
void
OnCollisionExit2D
()
{
// reset flags when we arent colliding with anything at all
onWallLeft
=
false
;
onWallRight
=
false
;
}
//
void OnCollisionExit2D() {
//
// reset flags when we arent colliding with anything at all
//
onWallLeft = false;
//
onWallRight = false;
//
}
}
Assets/Scripts/Player/Walk.cs
View file @
a76b053a
...
...
@@ -150,7 +150,7 @@ public class Walk : AbstractBehavior {
//slow down y velocity
if
(
body
.
velocity
.
y
<
clingSpeed
)
{
body
.
velocity
=
new
Vector2
(
body
.
velocity
.
x
,
-
clingSpeed
);
body
.
velocity
=
new
Vector2
(
0
,
-
clingSpeed
);
}
}
...
...
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