Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dyingIsMainstream
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gamejam-gpn15
dyingIsMainstream
Commits
26ecec69
Commit
26ecec69
authored
Jun 05, 2015
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify movement code
parent
9a05dc67
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
18 deletions
+6
-18
PlayerControl.cs
Assets/Scripts/PlayerControl.cs
+6
-18
No files found.
Assets/Scripts/PlayerControl.cs
View file @
26ecec69
...
@@ -117,39 +117,27 @@ public class PlayerControl : MonoBehaviour
...
@@ -117,39 +117,27 @@ public class PlayerControl : MonoBehaviour
}
}
else
else
{
{
bool
grounded
=
isGrounded
();
velocity
=
body2D
.
velocity
;
velocity
=
body2D
.
velocity
;
if
(
Input
.
GetKey
(
keyCodes
[(
int
)
Keys
.
Right
]))
if
(
Input
.
GetKey
(
keyCodes
[(
int
)
Keys
.
Right
]))
{
{
//normalizedHorizontalSpeed = 1;
velocity
.
x
=
runSpeed
;
//if (transform.localScale.x < 0f)
// transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
//go right:
velocity
=
new
Vector2
(
runSpeed
,
velocity
.
y
);
//if (_controller.isGrounded)
}
}
else
if
(
Input
.
GetKey
(
keyCodes
[(
int
)
Keys
.
Left
]))
else
if
(
Input
.
GetKey
(
keyCodes
[(
int
)
Keys
.
Left
]))
{
{
//normalizedHorizontalSpeed = -1;
velocity
.
x
=
-
runSpeed
;
//if (transform.localScale.x > 0f)
// transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
velocity
=
new
Vector2
(-
runSpeed
,
velocity
.
y
);
//if (_controller.isGrounded)
}
}
if
(
Input
.
GetKey
(
keyCodes
[(
int
)
Keys
.
Jump
]))
if
(
Input
.
GetKey
(
keyCodes
[(
int
)
Keys
.
Jump
]))
{
{
//to avoid DOUBLE JUMP
//to avoid DOUBLE JUMP
if
(
isGrounded
()
)
if
(
grounded
)
{
{
velocity
=
new
Vector2
(
velocity
.
x
,
targetJumpHeight
)
;
velocity
.
y
=
targetJumpHeight
;
}
}
}
}
// apply horizontal speed smoothing it
// apply horizontal speed smoothing it
var
smoothedMovementFactor
=
isGrounded
()
?
groundDamping
:
inAirDamping
;
// how fast do we change direction?
var
smoothedMovementFactor
=
isGrounded
()
?
groundDamping
:
inAirDamping
;
// how fast do we change direction?
velocity
.
x
=
Mathf
.
Lerp
(
velocity
.
x
,
0
,
Time
.
deltaTime
*
smoothedMovementFactor
);
velocity
.
x
=
Mathf
.
Lerp
(
velocity
.
x
,
0
,
Time
.
deltaTime
*
smoothedMovementFactor
);
...
...
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