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
fc4c13e0
Commit
fc4c13e0
authored
Jun 05, 2015
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve dashes
parent
3f2a02af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
60 deletions
+79
-60
PlayerControl.cs
Assets/Scripts/PlayerControl.cs
+79
-60
No files found.
Assets/Scripts/PlayerControl.cs
View file @
fc4c13e0
...
@@ -12,8 +12,13 @@ public class PlayerControl : MonoBehaviour
...
@@ -12,8 +12,13 @@ public class PlayerControl : MonoBehaviour
public
float
groundDamping
=
20f
;
// how fast do we change direction? higher means faster
public
float
groundDamping
=
20f
;
// how fast do we change direction? higher means faster
public
float
inAirDamping
=
5f
;
public
float
inAirDamping
=
5f
;
public
float
targetJumpHeight
=
2f
;
public
float
targetJumpHeight
=
2f
;
public
bool
canDash
=
true
;
public
float
lastDashStart
=
float
.
NegativeInfinity
;
public
float
dashCoolDown
=
0.25f
;
public
float
currentDashDirection
=
0.0f
;
public
float
dashDirection
=
1.0f
;
public
float
dashCompletionTime
=
0.25f
;
public
float
dashStartSpeed
=
20.0f
;
public
float
dashEndSpeed
=
8.0f
;
public
float
dashCoolDown
=
0.5f
;
// public float jumpWaitTime = 2.0;
// public float jumpWaitTime = 2.0;
[
HideInInspector
]
[
HideInInspector
]
...
@@ -93,82 +98,97 @@ public class PlayerControl : MonoBehaviour
...
@@ -93,82 +98,97 @@ public class PlayerControl : MonoBehaviour
if
(
_controller
.
isGrounded
)
if
(
_controller
.
isGrounded
)
velocity
.
y
=
0
;
velocity
.
y
=
0
;
if
(
Input
.
GetKey
(
goRightKeyCode
))
if
(
Input
.
GetKey
(
goRightKeyCode
))
{
normalizedHorizontalSpeed
=
1
;
if
(
transform
.
localScale
.
x
<
0f
)
transform
.
localScale
=
new
Vector3
(-
transform
.
localScale
.
x
,
transform
.
localScale
.
y
,
transform
.
localScale
.
z
);
//if (_controller.isGrounded)
}
else
if
(
Input
.
GetKey
(
goLeftKeyCode
))
{
{
normalizedHorizontalSpeed
=
-
1
;
dashDirection
=
1.0f
;
if
(
transform
.
localScale
.
x
>
0f
)
transform
.
localScale
=
new
Vector3
(-
transform
.
localScale
.
x
,
transform
.
localScale
.
y
,
transform
.
localScale
.
z
);
//if (_controller.isGrounded)
}
}
else
else
if
(
Input
.
GetKey
(
goLeftKeyCode
))
{
{
normalizedHorizontalSpeed
=
0
;
dashDirection
=
-
1.0f
;
//if (_controller.isGrounded)
}
}
if
(
canDash
&&
Input
.
GetKey
(
dashKeyCode
))
if
(
canDash
()
&&
Input
.
GetKey
(
dashKeyCode
))
{
{
float
direction
=
Mathf
.
Sign
(
transform
.
localScale
.
x
);
lastDashStart
=
Time
.
time
;
if
(
normalizedHorizontalSpeed
!=
0
)
currentDashDirection
=
dashDirection
;
{
// player pressed a movement button so prefer the new direction
direction
=
Mathf
.
Sign
(
normalizedHorizontalSpeed
);
}
normalizedHorizontalSpeed
=
5
*
direction
;
canDash
=
false
;
Invoke
(
"EnableDash"
,
dashCoolDown
);
}
}
if
(
Input
.
GetKeyDown
(
jumpKeyCode
))
if
(
isDashing
(
))
{
{
//to avoid DOUBLE JUMP
velocity
.
x
=
Mathf
.
Lerp
(
currentDashDirection
*
dashStartSpeed
,
currentDashDirection
*
dashEndSpeed
,
getDashTime
()
/
dashCompletionTime
);
if
(
_controller
.
isGrounded
)
velocity
.
y
=
0
;
{
velocity
.
y
=
Mathf
.
Sqrt
(
2f
*
targetJumpHeight
*
-
gravity
);
}
}
}
else
// apply horizontal speed smoothing it
var
smoothedMovementFactor
=
_controller
.
isGrounded
?
groundDamping
:
inAirDamping
;
// how fast do we change direction?
velocity
.
x
=
Mathf
.
Lerp
(
velocity
.
x
,
normalizedHorizontalSpeed
*
rawMovementDirection
*
runSpeed
,
Time
.
deltaTime
*
smoothedMovementFactor
);
// apply gravity before moving
velocity
.
y
+=
gravity
*
Time
.
deltaTime
;
_controller
.
move
(
velocity
*
Time
.
deltaTime
);
/*==========Power Ups // Bullet management ===*/
if
(
Input
.
GetKeyDown
(
shootKeyCode
))
{
{
if
(
Input
.
GetKey
(
goRightKeyCode
))
{
normalizedHorizontalSpeed
=
1
;
if
(
transform
.
localScale
.
x
<
0f
)
transform
.
localScale
=
new
Vector3
(-
transform
.
localScale
.
x
,
transform
.
localScale
.
y
,
transform
.
localScale
.
z
);
//if (_controller.isGrounded)
}
else
if
(
Input
.
GetKey
(
goLeftKeyCode
))
{
normalizedHorizontalSpeed
=
-
1
;
if
(
transform
.
localScale
.
x
>
0f
)
transform
.
localScale
=
new
Vector3
(-
transform
.
localScale
.
x
,
transform
.
localScale
.
y
,
transform
.
localScale
.
z
);
//if (_controller.isGrounded)
}
else
{
normalizedHorizontalSpeed
=
0
;
//if (_controller.isGrounded)
}
if
(
Input
.
GetKeyDown
(
jumpKeyCode
))
{
//to avoid DOUBLE JUMP
if
(
_controller
.
isGrounded
)
{
velocity
.
y
=
Mathf
.
Sqrt
(
2f
*
targetJumpHeight
*
-
gravity
);
}
}
// apply horizontal speed smoothing it
var
smoothedMovementFactor
=
_controller
.
isGrounded
?
groundDamping
:
inAirDamping
;
// how fast do we change direction?
velocity
.
x
=
Mathf
.
Lerp
(
velocity
.
x
,
normalizedHorizontalSpeed
*
rawMovementDirection
*
runSpeed
,
Time
.
deltaTime
*
smoothedMovementFactor
);
// apply gravity before moving
velocity
.
y
+=
gravity
*
Time
.
deltaTime
;
/*==========Power Ups // Bullet management ===*/
if
(
Input
.
GetKeyDown
(
shootKeyCode
))
{
Debug
.
Log
(
"Shoot pressed. Can shoot: "
+
canShoot
());
Debug
.
Log
(
"Shoot pressed. Can shoot: "
+
canShoot
());
if
(
canShoot
())
if
(
canShoot
())
{
{
shoot
();
shoot
();
coolDown
();
coolDown
();
}
}
}
}
}
_controller
.
move
(
velocity
*
Time
.
deltaTime
);
}
private
float
getDashTime
()
{
return
Time
.
time
-
lastDashStart
;
}
private
bool
isDashing
()
{
float
dashTime
=
getDashTime
();
return
0
<=
dashTime
&&
dashTime
<
dashCompletionTime
;
}
}
void
EnableDash
()
private
bool
canDash
()
{
{
canDash
=
true
;
return
getDashTime
()
>=
dashCompletionTime
+
dashCoolDown
;
}
}
/*==========Power Ups // Bullet management ===*/
/*==========Power Ups // Bullet management ===*/
...
@@ -229,4 +249,4 @@ public class PlayerControl : MonoBehaviour
...
@@ -229,4 +249,4 @@ public class PlayerControl : MonoBehaviour
return
(!
coolingDown
)
&&
powerUpType
!=
POWERUP_NONE
;
return
(!
coolingDown
)
&&
powerUpType
!=
POWERUP_NONE
;
}
}
}
}
\ No newline at end of file
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