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
568734b5
Commit
568734b5
authored
Feb 23, 2017
by
Jordan B Mckenney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated walk script
parent
c6d84b14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
6 deletions
+57
-6
Assets/Scripts/Player/Walk.cs
Assets/Scripts/Player/Walk.cs
+57
-6
ProjectSettings/TagManager.asset
ProjectSettings/TagManager.asset
+0
-0
No files found.
Assets/Scripts/Player/Walk.cs
View file @
568734b5
...
...
@@ -3,11 +3,14 @@ using System.Collections.Generic;
using
UnityEngine
;
public
class
Walk
:
AbstractBehavior
{
public
in
t
speed
;
public
floa
t
speed
;
private
float
airSpeed
;
public
float
airAcceleration
;
public
float
friction
;
public
float
wallClingTime
;
//time you will 'stick' to the wall after pressing the opposite direction
private
float
xScale
;
public
float
realSpeed
;
private
int
rightInt
=
0
;
private
int
leftInt
=
0
;
...
...
@@ -28,7 +31,8 @@ public class Walk : AbstractBehavior {
rightInt
=
0
;
leftInt
=
0
;
//rightTime = inputButtons[0].
rightTime
=
inputState
.
GetButtonHoldTime
(
right
);
leftTime
=
inputState
.
GetButtonHoldTime
(
left
);
if
(
inputState
.
GetButtonValue
(
right
))
rightInt
=
1
;
...
...
@@ -40,15 +44,40 @@ public class Walk : AbstractBehavior {
else
leftInt
=
0
;
if
(
collisionState
.
onGround
)
if
(
collisionState
.
onGround
)
//movement on ground
{
body
.
velocity
=
new
Vector2
(
speed
*
(
rightInt
+
leftInt
),
body
.
velocity
.
y
);
realSpeed
=
body
.
velocity
.
x
;
if
(
inputState
.
GetButtonValue
(
right
)
||
inputState
.
GetButtonValue
(
left
))
{
realSpeed
=
Mathf
.
Clamp
(
realSpeed
+
speed
*
(
rightInt
+
leftInt
),
-
speed
,
speed
);
}
else
{
if
(
realSpeed
!=
0
)
{
realSpeed
+=
(-
1
)
*
Mathf
.
Sign
(
realSpeed
)
*
friction
;
if
(
Mathf
.
Abs
(
realSpeed
)
<
friction
)
realSpeed
=
0
;
}
}
body
.
velocity
=
new
Vector2
(
realSpeed
,
body
.
velocity
.
y
);
}
else
if
(!
collisionState
.
onWall
)
{
airSpeed
=
body
.
velocity
.
x
;
if
(
inputState
.
GetButtonValue
(
right
)
||
inputState
.
GetButtonValue
(
left
))
{
airSpeed
=
Mathf
.
Clamp
(
airSpeed
+
airAcceleration
*
(
rightInt
+
leftInt
),
-
speed
,
speed
);
if
(
Mathf
.
Abs
(
airSpeed
)
<=
speed
)
airSpeed
=
Mathf
.
Clamp
(
airSpeed
+
airAcceleration
*
(
rightInt
+
leftInt
),
-
speed
,
speed
);
else
{
if
(
airSpeed
!=
0
)
{
airSpeed
+=
(-
1
)
*
Mathf
.
Sign
(
airSpeed
)
*
airAcceleration
;
if
(
Mathf
.
Abs
(
airSpeed
)
<
airAcceleration
)
airSpeed
=
0
;
}
}
}
else
{
...
...
@@ -59,9 +88,31 @@ public class Walk : AbstractBehavior {
}
}
body
.
velocity
=
new
Vector2
(
airSpeed
,
body
.
velocity
.
y
);
}
else
}
else
//handles on the wall
{
airSpeed
=
body
.
velocity
.
x
;
//only sets a change if the button has been held for a set time
if
(
rightTime
>=
wallClingTime
)
{
airSpeed
=
Mathf
.
Clamp
(
airSpeed
+
airAcceleration
*
(
rightInt
),
-
speed
,
speed
);
}
if
(
leftTime
>=
wallClingTime
)
{
airSpeed
=
Mathf
.
Clamp
(
airSpeed
+
airAcceleration
*
(
leftInt
),
-
speed
,
speed
);
}
//same as if not on wall and not pressing the buttons
if
(!
inputState
.
GetButtonValue
(
right
)
&&
!
inputState
.
GetButtonValue
(
left
))
{
if
(
airSpeed
!=
0
)
{
airSpeed
+=
(-
1
)
*
Mathf
.
Sign
(
airSpeed
)
*
airAcceleration
;
if
(
Mathf
.
Abs
(
airSpeed
)
<
airAcceleration
)
airSpeed
=
0
;
}
}
body
.
velocity
=
new
Vector2
(
airSpeed
,
body
.
velocity
.
y
);
}
//change localScale depending on direction
...
...
ProjectSettings/TagManager.asset
View file @
568734b5
No preview for this file type
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