Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
tetra-tower
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Oenos
tetra-tower
Commits
00f956ec
Commit
00f956ec
authored
Jan 30, 2019
by
16도재형
Committed by
18류지석
Jan 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
드드드 및 수평 이동 메커니즘 고침
parent
0a5cc655
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
85 deletions
+78
-85
Player.prefab
Assets/Prefabs/Characters/Player.prefab
+25
-11
PlayerController.cs
Assets/Scripts/Characters/PlayerController.cs
+53
-74
No files found.
Assets/Prefabs/Characters/Player.prefab
View file @
00f956ec
...
@@ -42,6 +42,7 @@ GameObject:
...
@@ -42,6 +42,7 @@ GameObject:
m_Component
:
m_Component
:
-
component
:
{
fileID
:
4710911479571038
}
-
component
:
{
fileID
:
4710911479571038
}
-
component
:
{
fileID
:
61129044981816742
}
-
component
:
{
fileID
:
61129044981816742
}
-
component
:
{
fileID
:
114402380471012178
}
m_Layer
:
0
m_Layer
:
0
m_Name
:
AttackColider
m_Name
:
AttackColider
m_TagString
:
Untagged
m_TagString
:
Untagged
...
@@ -92,7 +93,7 @@ Rigidbody2D:
...
@@ -92,7 +93,7 @@ Rigidbody2D:
m_AngularDrag
:
0.05
m_AngularDrag
:
0.05
m_GravityScale
:
5
m_GravityScale
:
5
m_Material
:
{
fileID
:
0
}
m_Material
:
{
fileID
:
0
}
m_Interpolate
:
0
m_Interpolate
:
1
m_SleepingMode
:
1
m_SleepingMode
:
1
m_CollisionDetection
:
1
m_CollisionDetection
:
1
m_Constraints
:
4
m_Constraints
:
4
...
@@ -176,19 +177,16 @@ MonoBehaviour:
...
@@ -176,19 +177,16 @@ MonoBehaviour:
m_Name
:
m_Name
:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
rbGravityScale
:
3
rbGravityScale
:
3
rbAttackGravityScale
:
3
rbAttackGravityScale
:
0.5
maxSpeed
:
3
maxSpeed
:
3
maxDashSpeed
:
6
maxDashSpeed
:
6
accerlation
:
1200
acceleration
:
20
deceleration
:
20
jumpSpeed
:
11
jumpSpeed
:
11
ropeSpeed
:
3
ropeSpeed
:
3
doubleJumpSpeed
:
10
doubleJumpSpeed
:
10
dashAccerlation
:
2000
dashAcceleration
:
50
isDashing
:
0
platformCollider
:
{
fileID
:
0
}
platformArray
:
[]
horizontal
:
0
horizontalRaw
:
0
dashStart
:
0
groundLayer
:
groundLayer
:
serializedVersion
:
2
serializedVersion
:
2
m_Bits
:
256
m_Bits
:
256
...
@@ -207,6 +205,22 @@ MonoBehaviour:
...
@@ -207,6 +205,22 @@ MonoBehaviour:
ropeDown
:
0.8
ropeDown
:
0.8
playerState
:
0
playerState
:
0
previousState
:
0
previousState
:
0
---
!u!114
&114402380471012178
MonoBehaviour
:
m_ObjectHideFlags
:
1
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInternal
:
{
fileID
:
100100000
}
m_GameObject
:
{
fileID
:
1862495014651308
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
64f948f7c7aacab409fe963a6f9e0d2a
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
damage
:
0
knockBackMultiplier
:
1
debuffNum
:
0
debuffType
:
debuffTime
:
00000000000000000000000000000000000000000000000000000000000000000000000000000000
---
!u!114
&114880704145925944
---
!u!114
&114880704145925944
MonoBehaviour
:
MonoBehaviour
:
m_ObjectHideFlags
:
1
m_ObjectHideFlags
:
1
...
@@ -218,13 +232,13 @@ MonoBehaviour:
...
@@ -218,13 +232,13 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
4ab58a64164eb984d8683df370ddce96
,
type
:
3
}
m_Script
:
{
fileID
:
11500000
,
guid
:
4ab58a64164eb984d8683df370ddce96
,
type
:
3
}
m_Name
:
m_Name
:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
state
:
0
attackRaw
:
attackRaw
:
-
0
-
0
-
0
-
0
-
0
-
0
attackKeyState
:
000000000000000000000000
attackKeyState
:
000000000000000000000000
cancel
:
0
cancelRaw
:
0
cancelKeyState
:
0
playingSkill
:
0
playingSkill
:
0
comboTime
:
1
comboTime
:
1
time
:
{
fileID
:
0
}
time
:
{
fileID
:
0
}
...
...
Assets/Scripts/Characters/PlayerController.cs
View file @
00f956ec
...
@@ -17,7 +17,9 @@ public class PlayerController : MonoBehaviour
...
@@ -17,7 +17,9 @@ public class PlayerController : MonoBehaviour
[
SerializeField
]
[
SerializeField
]
private
float
maxDashSpeed
;
private
float
maxDashSpeed
;
[
SerializeField
]
[
SerializeField
]
private
float
accerlation
;
private
float
acceleration
;
[
SerializeField
]
private
float
deceleration
;
[
SerializeField
]
[
SerializeField
]
private
float
jumpSpeed
;
private
float
jumpSpeed
;
[
SerializeField
]
[
SerializeField
]
...
@@ -25,9 +27,7 @@ public class PlayerController : MonoBehaviour
...
@@ -25,9 +27,7 @@ public class PlayerController : MonoBehaviour
[
SerializeField
]
[
SerializeField
]
private
float
doubleJumpSpeed
;
private
float
doubleJumpSpeed
;
[
SerializeField
]
[
SerializeField
]
private
float
dashAccerlation
;
private
float
dashAcceleration
;
[
SerializeField
]
private
bool
isDashing
=
false
;
public
Collider2D
platformCollider
;
public
Collider2D
platformCollider
;
// Bool values for jump & doublejump
// Bool values for jump & doublejump
private
bool
isGrounded
=
true
;
private
bool
isGrounded
=
true
;
...
@@ -35,14 +35,12 @@ public class PlayerController : MonoBehaviour
...
@@ -35,14 +35,12 @@ public class PlayerController : MonoBehaviour
private
bool
isDownPlatform
=
false
;
private
bool
isDownPlatform
=
false
;
private
bool
ropeEnabled
=
true
;
private
bool
ropeEnabled
=
true
;
// Inputs
// Inputs
[
SerializeField
]
private
float
horizontal
=
0
;
private
float
horizontal
=
0
;
[
SerializeField
]
private
float
horizontalRaw
=
0
;
private
float
horizontalRaw
=
0
;
private
float
verticalRaw
=
0
;
private
float
verticalRaw
=
0
;
private
bool
upKeyDown
=
false
;
private
bool
jump
=
false
;
private
bool
jump
=
false
;
[
SerializeField
]
private
bool
dash
=
false
;
private
int
dashStart
=
0
;
// Variables for IsGrounded()
// Variables for IsGrounded()
[
SerializeField
]
[
SerializeField
]
private
LayerMask
groundLayer
;
private
LayerMask
groundLayer
;
...
@@ -70,9 +68,13 @@ public class PlayerController : MonoBehaviour
...
@@ -70,9 +68,13 @@ public class PlayerController : MonoBehaviour
void
Update
()
void
Update
()
{
{
float
previous
=
verticalRaw
;
horizontal
=
Input
.
GetAxis
(
"Horizontal"
);
horizontal
=
Input
.
GetAxis
(
"Horizontal"
);
horizontalRaw
=
Input
.
GetAxisRaw
(
"Horizontal"
);
horizontalRaw
=
Input
.
GetAxisRaw
(
"Horizontal"
);
verticalRaw
=
Input
.
GetAxisRaw
(
"Vertical"
);
verticalRaw
=
Input
.
GetAxisRaw
(
"Vertical"
);
dash
=
Input
.
GetButton
(
"Dash"
);
if
(!
upKeyDown
)
upKeyDown
=
previous
<=
0
&&
verticalRaw
>
0
;
if
(
Input
.
GetButtonDown
(
"Jump"
))
if
(
Input
.
GetButtonDown
(
"Jump"
))
{
{
...
@@ -98,12 +100,12 @@ public class PlayerController : MonoBehaviour
...
@@ -98,12 +100,12 @@ public class PlayerController : MonoBehaviour
{
{
if
(
isGrounded
)
if
(
isGrounded
)
{
{
if
(
horizontalRaw
==
1f
)
transform
.
localScale
=
new
Vector3
(-
1f
,
transform
.
localScale
.
y
,
transform
.
localScale
.
z
);
if
(
horizontalRaw
>
0
)
transform
.
localScale
=
new
Vector3
(-
1
,
1
,
1
);
else
if
(
horizontalRaw
==
-
1f
)
transform
.
localScale
=
new
Vector3
(
1f
,
transform
.
localScale
.
y
,
transform
.
localScale
.
z
);
else
if
(
horizontalRaw
<
0
)
transform
.
localScale
=
new
Vector3
(
1
,
1
,
1
);
}
}
// Platform downjump
if
(
verticalRaw
==
-
1
&&
!
isDownPlatform
)
if
(
verticalRaw
<
0
&&
!
isDownPlatform
)
{
{
Room
curRoom
=
MapManager
.
mapGrid
[
Player
.
tx
,
Player
.
ty
];
Room
curRoom
=
MapManager
.
mapGrid
[
Player
.
tx
,
Player
.
ty
];
platformCollider
=
curRoom
.
GetComponentInChildren
<
RoomInGame
>().
transform
.
Find
(
"platform"
).
GetComponent
<
CompositeCollider2D
>();
platformCollider
=
curRoom
.
GetComponentInChildren
<
RoomInGame
>().
transform
.
Find
(
"platform"
).
GetComponent
<
CompositeCollider2D
>();
...
@@ -114,106 +116,82 @@ public class PlayerController : MonoBehaviour
...
@@ -114,106 +116,82 @@ public class PlayerController : MonoBehaviour
{
{
if
(
playerState
==
PlayerState
.
Rope
)
if
(
playerState
==
PlayerState
.
Rope
)
{
{
if
(
horizontalRaw
!=
0f
&&
verticalRaw
==
0f
)
// Horizontal move in rope
if
(
horizontal
!=
0
&&
verticalRaw
==
0
)
{
{
playerState
=
PlayerState
.
Idle
;
playerState
=
PlayerState
.
Idle
;
rb
.
gravityScale
=
rbGravityScale
;
rb
.
gravityScale
=
rbGravityScale
;
StartCoroutine
(
RopeDelay
());
StartCoroutine
(
RopeDelay
());
}
}
rb
.
velocity
=
new
Vector2
(
0f
,
verticalRaw
*
ropeSpeed
);
// Vertical move in rope
else
{
rb
.
velocity
=
new
Vector2
(
0
,
verticalRaw
*
ropeSpeed
);
}
}
}
else
if
(
verticalRaw
!=
0
&&
ropeEnabled
&&
horizontal
Raw
==
0
)
else
if
(
verticalRaw
!=
0
&&
ropeEnabled
&&
horizontal
==
0
)
{
{
playerState
=
PlayerState
.
Rope
;
playerState
=
PlayerState
.
Rope
;
rb
.
gravityScale
=
0
f
;
rb
.
gravityScale
=
0
;
transform
.
position
=
new
Vector2
(
Mathf
.
Round
(
transform
.
position
.
x
-
0.5f
)
+
0.5f
,
transform
.
position
.
y
);
transform
.
position
=
new
Vector2
(
Mathf
.
Round
(
transform
.
position
.
x
-
0.5f
)
+
0.5f
,
transform
.
position
.
y
);
rb
.
velocity
=
new
Vector2
(
0f
,
0f
)
;
rb
.
velocity
=
Vector2
.
zero
;
}
}
anim
.
SetFloat
(
"ropeUpDown"
,
verticalRaw
);
anim
.
SetFloat
(
"ropeUpDown"
,
verticalRaw
);
}
}
else
else
{
{
playerState
=
PlayerState
.
Idle
;
rb
.
gravityScale
=
rbGravityScale
;
rb
.
gravityScale
=
rbGravityScale
;
playerState
=
PlayerState
.
Idle
;
}
}
if
(
playerState
!=
PlayerState
.
Rope
)
if
(
playerState
!=
PlayerState
.
Rope
)
{
{
float
vertical
=
rb
.
velocity
.
y
;
float
xVelocity
=
rb
.
velocity
.
x
;
if
(
jump
)
float
yVelocity
=
rb
.
velocity
.
y
;
float
airResistance
=
isGrounded
?
1f
:
0.5f
;
// Jump
if
(
jump
||
upKeyDown
)
{
{
if
(
isGrounded
)
if
(
isGrounded
)
{
{
vertical
=
jumpSpeed
;
yVelocity
=
jumpSpeed
;
}
}
else
if
(
isJumpable
)
else
if
(
isJumpable
)
{
{
vertical
=
doubleJumpSpeed
;
yVelocity
=
doubleJumpSpeed
;
isJumpable
=
false
;
isJumpable
=
false
;
}
}
}
}
if
(!
isGrounded
)
if
(!
isGrounded
)
{
{
if
(
vertical
>
0
)
playerState
=
PlayerState
.
GoingUp
;
playerState
=
(
yVelocity
>
0
)
?
PlayerState
.
GoingUp
:
PlayerState
.
GoingDown
;
else
playerState
=
PlayerState
.
GoingDown
;
rb
.
gravityScale
=
rbGravityScale
;
}
}
// Walk & Dash
if
(
horizontalRaw
!=
0
)
if
(
horizontalRaw
==
0
)
{
if
(
horizontal
!=
1
&&
horizontal
!=
-
1
&&
dashStart
==
0
)
{
//짧게 눌렀을 때
dashStart
=
1
;
}
}
if
(
horizontalRaw
==
0
&&
horizontal
!=
0
&&
dashStart
==
1
)
{
{
//방금 뗐을때
float
direction
=
Mathf
.
Sign
(
xVelocity
);
dashStart
=
2
;
xVelocity
=
Mathf
.
Abs
(
xVelocity
)
-
deceleration
*
airResistance
*
Time
.
fixedDeltaTime
;
//이제 빠르게 켜면 됨
if
(
xVelocity
<
0
)
xVelocity
=
0
;
xVelocity
*=
direction
;
if
(
isGrounded
)
playerState
=
PlayerState
.
Idle
;
}
}
if
(
dashStart
==
2
&&
horizontalRaw
!=
0
)
else
if
(
dash
)
{
{
isDashing
=
true
;
xVelocity
+=
Mathf
.
Sign
(
horizontal
)
*
dashAcceleration
*
airResistance
*
Time
.
fixedDeltaTime
;
xVelocity
=
Mathf
.
Clamp
(
xVelocity
,
-
maxDashSpeed
,
maxDashSpeed
);
if
(
isGrounded
)
playerState
=
PlayerState
.
Run
;
}
}
if
(
horizontalRaw
==
0
&&
horizontal
==
0
)
{
dashStart
=
0
;
isDashing
=
false
;
}
if
(
isDashing
)
rb
.
AddForce
(
horizontalRaw
*
dashAccerlation
*
Time
.
smoothDeltaTime
*
Vector2
.
right
);
else
else
rb
.
AddForce
(
horizontalRaw
*
accerlation
*
Time
.
smoothDeltaTime
*
Vector2
.
right
);
if
(
isGrounded
)
{
{
if
(
horizontalRaw
==
0
)
playerState
=
PlayerState
.
Idle
;
float
analogSpeed
=
Mathf
.
Abs
(
horizontal
);
else
xVelocity
+=
Mathf
.
Sign
(
horizontal
)
*
acceleration
*
airResistance
*
Time
.
fixedDeltaTime
;
{
xVelocity
=
Mathf
.
Clamp
(
xVelocity
,
-
maxSpeed
*
analogSpeed
,
maxSpeed
*
analogSpeed
);
if
(
isDashing
)
playerState
=
PlayerState
.
Run
;
if
(
isGrounded
)
playerState
=
PlayerState
.
Walk
;
else
playerState
=
PlayerState
.
Walk
;
}
}
}
rb
.
velocity
=
new
Vector2
(
xVelocity
,
yVelocity
);
if
(((
horizontalRaw
==
0
)
||
(
rb
.
velocity
.
x
>
0
&&
horizontalRaw
<
0
)
||
(
rb
.
velocity
.
x
<
0
&&
horizontalRaw
>
0
))
&&
(
isGrounded
))
{
// rb.AddForce(rb.velocity.x * (-100f) * Vector2.right * Time.smoothDeltaTime);
rb
.
velocity
=
new
Vector2
(
rb
.
velocity
.
x
/
(
1.5f
),
rb
.
velocity
.
y
);
}
if
(
isDashing
)
rb
.
velocity
=
new
Vector2
(
Mathf
.
Clamp
(
rb
.
velocity
.
x
,
-
maxDashSpeed
,
maxDashSpeed
),
vertical
);
else
rb
.
velocity
=
new
Vector2
(
Mathf
.
Clamp
(
rb
.
velocity
.
x
,
-
maxSpeed
,
maxSpeed
),
vertical
);
}
}
}
}
if
(
previousState
!=
playerState
)
if
(
previousState
!=
playerState
)
...
@@ -230,6 +208,7 @@ public class PlayerController : MonoBehaviour
...
@@ -230,6 +208,7 @@ public class PlayerController : MonoBehaviour
previousState
=
playerState
;
previousState
=
playerState
;
}
}
upKeyDown
=
false
;
jump
=
false
;
jump
=
false
;
}
}
bool
IsGrounded
()
// Is player grounded?
bool
IsGrounded
()
// Is player grounded?
...
@@ -260,7 +239,7 @@ public class PlayerController : MonoBehaviour
...
@@ -260,7 +239,7 @@ public class PlayerController : MonoBehaviour
{
{
Physics2D
.
IgnoreCollision
(
platformCollider
,
transform
.
GetComponent
<
Collider2D
>(),
true
);
Physics2D
.
IgnoreCollision
(
platformCollider
,
transform
.
GetComponent
<
Collider2D
>(),
true
);
yield
return
new
WaitForSeconds
(
0.3f
);
yield
return
new
WaitForSeconds
(
0.3f
);
while
(
playerState
==
PlayerState
.
Rope
)
yield
return
n
ew
WaitForSeconds
(
0.1f
)
;
while
(
playerState
==
PlayerState
.
Rope
)
yield
return
n
ull
;
Physics2D
.
IgnoreCollision
(
platformCollider
,
transform
.
GetComponent
<
Collider2D
>(),
false
);
Physics2D
.
IgnoreCollision
(
platformCollider
,
transform
.
GetComponent
<
Collider2D
>(),
false
);
isDownPlatform
=
false
;
isDownPlatform
=
false
;
}
}
...
...
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