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
b98dc720
Commit
b98dc720
authored
Jun 04, 2015
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make player dash with 'down' key
parent
d9140ec0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
4 deletions
+24
-4
PlayerControl.cs
Assets/Scripts/PlayerControl.cs
+24
-4
No files found.
Assets/Scripts/PlayerControl.cs
View file @
b98dc720
...
@@ -11,6 +11,8 @@ public class PlayerControl : MonoBehaviour
...
@@ -11,6 +11,8 @@ 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
dashCoolDown
=
0.25f
;
// public float jumpWaitTime = 2.0;
// public float jumpWaitTime = 2.0;
[
HideInInspector
]
[
HideInInspector
]
...
@@ -25,7 +27,7 @@ public class PlayerControl : MonoBehaviour
...
@@ -25,7 +27,7 @@ public class PlayerControl : MonoBehaviour
public
Vector3
velocity
;
public
Vector3
velocity
;
public
int
playerNumber
=
1
;
//gibt an, ob es sich um player one, player two, etc. handelt. sollte nicht 0 sein;
public
int
playerNumber
=
1
;
//gibt an, ob es sich um player one, player two, etc. handelt. sollte nicht 0 sein;
KeyCode
goRightKeyCode
,
goLeftKeyCode
,
jumpKeyCode
;
KeyCode
goRightKeyCode
,
goLeftKeyCode
,
jumpKeyCode
,
dashKeyCode
;
void
Start
()
void
Start
()
{
{
...
@@ -35,10 +37,10 @@ public class PlayerControl : MonoBehaviour
...
@@ -35,10 +37,10 @@ public class PlayerControl : MonoBehaviour
switch
(
playerNumber
)
switch
(
playerNumber
)
{
{
case
1
:
case
1
:
setKeyCodes
(
KeyCode
.
D
,
KeyCode
.
A
,
KeyCode
.
W
);
setKeyCodes
(
KeyCode
.
D
,
KeyCode
.
A
,
KeyCode
.
W
,
KeyCode
.
S
);
break
;
break
;
case
2
:
case
2
:
setKeyCodes
(
KeyCode
.
RightArrow
,
KeyCode
.
LeftArrow
,
KeyCode
.
UpArrow
);
setKeyCodes
(
KeyCode
.
RightArrow
,
KeyCode
.
LeftArrow
,
KeyCode
.
UpArrow
,
KeyCode
.
DownArrow
);
break
;
break
;
//TODO player 3 and 4
//TODO player 3 and 4
default
:
default
:
...
@@ -46,11 +48,12 @@ public class PlayerControl : MonoBehaviour
...
@@ -46,11 +48,12 @@ public class PlayerControl : MonoBehaviour
}
}
}
}
private
void
setKeyCodes
(
KeyCode
right
,
KeyCode
left
,
KeyCode
up
)
private
void
setKeyCodes
(
KeyCode
right
,
KeyCode
left
,
KeyCode
up
,
KeyCode
dash
)
{
{
goRightKeyCode
=
right
;
goRightKeyCode
=
right
;
goLeftKeyCode
=
left
;
goLeftKeyCode
=
left
;
jumpKeyCode
=
up
;
jumpKeyCode
=
up
;
dashKeyCode
=
dash
;
}
}
...
@@ -97,6 +100,19 @@ public class PlayerControl : MonoBehaviour
...
@@ -97,6 +100,19 @@ public class PlayerControl : MonoBehaviour
//if (_controller.isGrounded)
//if (_controller.isGrounded)
}
}
if
(
canDash
&&
Input
.
GetKey
(
dashKeyCode
))
{
float
direction
=
Mathf
.
Sign
(
transform
.
localScale
.
x
);
if
(
normalizedHorizontalSpeed
!=
0
)
{
// 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
(
Input
.
GetKeyDown
(
jumpKeyCode
))
{
{
...
@@ -119,4 +135,8 @@ public class PlayerControl : MonoBehaviour
...
@@ -119,4 +135,8 @@ public class PlayerControl : MonoBehaviour
}
}
void
EnableDash
()
{
canDash
=
true
;
}
}
}
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