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
ba6bce1a
Commit
ba6bce1a
authored
Jan 31, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'tetra-tower/ddd' into tetris
parents
538d6e4d
bdef85c4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
127 deletions
+107
-127
Player.prefab
Assets/Prefabs/Characters/Player.prefab
+31
-21
PlayerController.cs
Assets/Scripts/Characters/PlayerController.cs
+76
-106
No files found.
Assets/Prefabs/Characters/Player.prefab
View file @
ba6bce1a
...
...
@@ -42,6 +42,7 @@ GameObject:
m_Component
:
-
component
:
{
fileID
:
4710911479571038
}
-
component
:
{
fileID
:
61129044981816742
}
-
component
:
{
fileID
:
114402380471012178
}
m_Layer
:
0
m_Name
:
AttackColider
m_TagString
:
Untagged
...
...
@@ -92,7 +93,7 @@ Rigidbody2D:
m_AngularDrag
:
0.05
m_GravityScale
:
5
m_Material
:
{
fileID
:
0
}
m_Interpolate
:
0
m_Interpolate
:
1
m_SleepingMode
:
1
m_CollisionDetection
:
1
m_Constraints
:
4
...
...
@@ -176,37 +177,46 @@ MonoBehaviour:
m_Name
:
m_EditorClassIdentifier
:
rbGravityScale
:
3
rbAttackGravityScale
:
3
maxSpeed
:
3
maxDashSpeed
:
6
accerlation
:
1200
rbAttackGravityScale
:
0.5
maxSpeed
:
4
maxDashSpeed
:
7
acceleration
:
20
deceleration
:
20
jumpSpeed
:
11
ropeSpeed
:
3
doubleJumpSpeed
:
10
dashAccerlation
:
2000
isDashing
:
0
platformArray
:
[]
horizontal
:
0
horizontalRaw
:
0
dashStart
:
0
dashAcceleration
:
50
platformCollider
:
{
fileID
:
0
}
groundLayer
:
serializedVersion
:
2
m_Bits
:
256
m_Bits
:
6400
ropeLayer
:
serializedVersion
:
2
m_Bits
:
512
boxHeight
:
0.3
ropeUp
:
0.6
ropeDown
:
0.8
platformLayer
:
serializedVersion
:
2
m_Bits
:
2048
outerwallLayer
:
serializedVersion
:
2
m_Bits
:
4096
ropeDistance
:
0.3
rayDistance
:
1
ropeUp
:
0.6
ropeDown
:
0.8
playerState
:
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
MonoBehaviour
:
m_ObjectHideFlags
:
1
...
...
@@ -218,13 +228,13 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
4ab58a64164eb984d8683df370ddce96
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
state
:
0
attackRaw
:
-
0
-
0
-
0
attackKeyState
:
000000000000000000000000
cancel
:
0
cancelRaw
:
0
cancelKeyState
:
0
playingSkill
:
0
comboTime
:
1
time
:
{
fileID
:
0
}
...
...
Assets/Scripts/Characters/PlayerController.cs
View file @
ba6bce1a
...
...
@@ -17,7 +17,9 @@ public class PlayerController : MonoBehaviour
[
SerializeField
]
private
float
maxDashSpeed
;
[
SerializeField
]
private
float
accerlation
;
private
float
acceleration
;
[
SerializeField
]
private
float
deceleration
;
[
SerializeField
]
private
float
jumpSpeed
;
[
SerializeField
]
...
...
@@ -25,9 +27,7 @@ public class PlayerController : MonoBehaviour
[
SerializeField
]
private
float
doubleJumpSpeed
;
[
SerializeField
]
private
float
dashAccerlation
;
[
SerializeField
]
private
bool
isDashing
=
false
;
private
float
dashAcceleration
;
public
Collider2D
platformCollider
;
// Bool values for jump & doublejump
private
bool
isGrounded
=
true
;
...
...
@@ -35,30 +35,24 @@ public class PlayerController : MonoBehaviour
private
bool
isDownPlatform
=
false
;
private
bool
ropeEnabled
=
true
;
// Inputs
[
SerializeField
]
private
float
horizontal
=
0
;
[
SerializeField
]
private
float
horizontalRaw
=
0
;
private
float
verticalRaw
=
0
;
private
bool
upKeyDown
=
false
;
private
bool
downKeyDown
=
false
;
private
bool
jump
=
false
;
[
SerializeField
]
private
int
dashStart
=
0
;
// Variables for IsGrounded()
private
bool
dash
=
false
;
// Variables for collsiion checking
[
SerializeField
]
private
LayerMask
groundLayer
;
[
SerializeField
]
private
LayerMask
ropeLayer
;
[
SerializeField
]
private
LayerMask
platformLayer
;
[
SerializeField
]
private
LayerMask
outerwallLayer
;
[
SerializeField
]
private
float
ropeDistance
=
0.3f
;
[
SerializeField
]
private
float
rayDistance
;
private
float
boxHeight
;
[
SerializeField
]
private
float
ropeUp
,
ropeDown
;
[
SerializeField
]
private
LayerMask
platformLayer
;
public
PlayerState
playerState
,
previousState
;
...
...
@@ -70,9 +64,14 @@ public class PlayerController : MonoBehaviour
void
Update
()
{
float
previous
=
verticalRaw
;
horizontal
=
Input
.
GetAxis
(
"Horizontal"
);
horizontalRaw
=
Input
.
GetAxisRaw
(
"Horizontal"
);
verticalRaw
=
Input
.
GetAxisRaw
(
"Vertical"
);
if
(
isGrounded
)
dash
=
Input
.
GetButton
(
"Dash"
);
if
(!
upKeyDown
)
upKeyDown
=
previous
<=
0
&&
verticalRaw
>
0
;
if
(!
downKeyDown
)
downKeyDown
=
previous
>=
0
&&
verticalRaw
<
0
;
if
(
Input
.
GetButtonDown
(
"Jump"
))
{
...
...
@@ -98,122 +97,97 @@ public class PlayerController : MonoBehaviour
{
if
(
isGrounded
)
{
if
(
horizontalRaw
==
1f
)
transform
.
localScale
=
new
Vector3
(-
1f
,
transform
.
localScale
.
y
,
transform
.
localScale
.
z
);
else
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
<
0
)
transform
.
localScale
=
new
Vector3
(
1
,
1
,
1
);
}
if
(
verticalRaw
==
-
1
&&
!
isDownPlatform
)
// Platform downjump
if
(
OnPlatform
()
&&
downKeyDown
)
{
Room
curRoom
=
MapManager
.
mapGrid
[
Player
.
tx
,
Player
.
ty
];
platformCollider
=
curRoom
.
GetComponentInChildren
<
RoomInGame
>().
transform
.
Find
(
"platform"
).
GetComponent
<
CompositeCollider2D
>();
isDownPlatform
=
true
;
StartCoroutine
(
DownPlatform
());
}
if
(
IsInRope
())
{
if
(
playerState
==
PlayerState
.
Rope
)
{
if
(
horizontalRaw
!=
0f
&&
verticalRaw
==
0f
)
// Jump or Horizontal move in rope
if
(
jump
||
horizontal
!=
0
)
{
playerState
=
PlayerState
.
Idle
;
rb
.
gravityScale
=
rbGravityScale
;
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
;
rb
.
gravityScale
=
0
f
;
rb
.
gravityScale
=
0
;
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
);
}
else
{
playerState
=
PlayerState
.
Idle
;
rb
.
gravityScale
=
rbGravityScale
;
playerState
=
PlayerState
.
Idle
;
}
if
(
playerState
!=
PlayerState
.
Rope
)
{
float
vertical
=
rb
.
velocity
.
y
;
if
(
jump
)
float
xVelocity
=
rb
.
velocity
.
x
;
float
yVelocity
=
rb
.
velocity
.
y
;
float
airResistance
=
isGrounded
?
1f
:
0.5f
;
// Jump
if
(
jump
||
upKeyDown
)
{
if
(
isGrounded
)
{
vertical
=
jumpSpeed
;
yVelocity
=
jumpSpeed
;
}
else
if
(
isJumpable
)
{
vertical
=
doubleJumpSpeed
;
yVelocity
=
doubleJumpSpeed
;
isJumpable
=
false
;
}
}
if
(!
isGrounded
)
{
if
(
vertical
>
0
)
playerState
=
PlayerState
.
GoingUp
;
else
playerState
=
PlayerState
.
GoingDown
;
rb
.
gravityScale
=
rbGravityScale
;
playerState
=
(
yVelocity
>
0
)
?
PlayerState
.
GoingUp
:
PlayerState
.
GoingDown
;
}
if
(
horizontalRaw
!
=
0
)
// Walk & Dash
if
(
horizontalRaw
=
=
0
)
{
if
(
horizontal
!=
1
&&
horizontal
!=
-
1
&&
dashStart
==
0
)
{
//짧게 눌렀을 때
dashStart
=
1
;
}
float
direction
=
Mathf
.
Sign
(
xVelocity
);
xVelocity
=
Mathf
.
Abs
(
xVelocity
)
-
deceleration
*
airResistance
*
Time
.
fixedDeltaTime
;
if
(
xVelocity
<
0
)
xVelocity
=
0
;
xVelocity
*=
direction
;
if
(
isGrounded
)
playerState
=
PlayerState
.
Idle
;
}
if
(
horizontalRaw
==
0
&&
horizontal
!=
0
&&
dashStart
==
1
)
else
if
(
dash
)
{
//방금 뗐을때
dashStart
=
2
;
//이제 빠르게 켜면 됨
xVelocity
+=
Mathf
.
Sign
(
horizontal
)
*
dashAcceleration
*
airResistance
*
Time
.
fixedDeltaTime
;
xVelocity
=
Mathf
.
Clamp
(
xVelocity
,
-
maxDashSpeed
,
maxDashSpeed
)
;
if
(
isGrounded
)
playerState
=
PlayerState
.
Run
;
}
if
(
dashStart
==
2
&&
horizontalRaw
!=
0
)
{
isDashing
=
true
;
}
if
(
horizontalRaw
==
0
&&
horizontal
==
0
)
{
dashStart
=
0
;
isDashing
=
false
;
}
if
(
isDashing
)
rb
.
AddForce
(
horizontalRaw
*
dashAccerlation
*
Time
.
smoothDeltaTime
*
Vector2
.
right
);
else
rb
.
AddForce
(
horizontalRaw
*
accerlation
*
Time
.
smoothDeltaTime
*
Vector2
.
right
);
if
(
isGrounded
)
{
if
(
horizontalRaw
==
0
)
playerState
=
PlayerState
.
Idle
;
else
{
if
(
isDashing
)
playerState
=
PlayerState
.
Run
;
else
playerState
=
PlayerState
.
Walk
;
}
float
analogSpeed
=
Mathf
.
Abs
(
horizontal
);
xVelocity
+=
Mathf
.
Sign
(
horizontal
)
*
acceleration
*
airResistance
*
Time
.
fixedDeltaTime
;
xVelocity
=
Mathf
.
Clamp
(
xVelocity
,
-
maxSpeed
*
analogSpeed
,
maxSpeed
*
analogSpeed
);
if
(
isGrounded
)
playerState
=
PlayerState
.
Walk
;
}
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
);
rb
.
velocity
=
new
Vector2
(
xVelocity
,
yVelocity
);
}
}
if
(
previousState
!=
playerState
)
...
...
@@ -230,47 +204,43 @@ public class PlayerController : MonoBehaviour
previousState
=
playerState
;
}
upKeyDown
=
false
;
downKeyDown
=
false
;
jump
=
false
;
}
bool
IsGrounded
()
// Is player grounded?
{
RaycastHit2D
hit1
=
Physics2D
.
Raycast
(
transform
.
position
+
new
Vector3
(
Player
.
X
/
2f
,
0
,
0
),
Vector2
.
down
,
rayDistance
,
groundLayer
);
RaycastHit2D
hit2
=
Physics2D
.
Raycast
(
transform
.
position
+
new
Vector3
(
Player
.
X
/
2f
,
0
,
0
),
Vector2
.
down
,
rayDistance
,
platformLayer
);
RaycastHit2D
hit3
=
Physics2D
.
Raycast
(
transform
.
position
+
new
Vector3
(
Player
.
X
/
2f
,
0
,
0
),
Vector2
.
down
,
rayDistance
,
outerwallLayer
);
RaycastHit2D
hit4
=
Physics2D
.
Raycast
(
transform
.
position
-
new
Vector3
(
Player
.
X
/
2f
,
0
,
0
),
Vector2
.
down
,
rayDistance
,
groundLayer
);
RaycastHit2D
hit5
=
Physics2D
.
Raycast
(
transform
.
position
-
new
Vector3
(
Player
.
X
/
2f
,
0
,
0
),
Vector2
.
down
,
rayDistance
,
platformLayer
);
RaycastHit2D
hit6
=
Physics2D
.
Raycast
(
transform
.
position
-
new
Vector3
(
Player
.
X
/
2f
,
0
,
0
),
Vector2
.
down
,
rayDistance
,
outerwallLayer
);
Debug
.
DrawRay
(
transform
.
position
+
new
Vector3
(
Player
.
X
/
2f
,
0
,
0
),
rayDistance
*
Vector2
.
down
,
Color
.
white
);
return
(
hit1
.
collider
!=
null
||
hit2
.
collider
!=
null
||
hit3
.
collider
!=
null
||
hit4
.
collider
!=
null
||
hit5
.
collider
!=
null
||
hit6
.
collider
!=
null
)
&&
rb
.
velocity
.
y
==
0
;
//플랫폼 점프 버그 방지
RaycastHit2D
hit
=
Physics2D
.
BoxCast
(
transform
.
position
,
new
Vector2
(
Player
.
X
,
boxHeight
),
0
,
Vector2
.
down
,
Player
.
Y
/
2f
,
groundLayer
);
Debug
.
DrawLine
(
transform
.
position
+
new
Vector3
(
0
,
-
Player
.
Y
/
2f
)
+
new
Vector3
(-
Player
.
X
,
-
boxHeight
,
0
)
/
2
,
transform
.
position
+
new
Vector3
(
0
,
-
Player
.
Y
/
2f
)
+
new
Vector3
(
Player
.
X
,
-
boxHeight
,
0
)
/
2
);
return
hit
.
collider
!=
null
&&
rb
.
velocity
.
y
==
0
;
// 플랫폼 점프 버그 방지
}
bool
IsInRope
()
// Is player in rope?
{
RaycastHit2D
hit1
=
Physics2D
.
Raycast
(
transform
.
position
+
ropeUp
*
Vector3
.
up
,
Vector2
.
right
,
ropeDistance
,
ropeLayer
);
RaycastHit2D
hit2
=
Physics2D
.
Raycast
(
transform
.
position
+
ropeUp
*
Vector3
.
up
,
Vector2
.
left
,
ropeDistance
,
ropeLayer
);
RaycastHit2D
hit3
=
Physics2D
.
Raycast
(
transform
.
position
-
ropeDown
*
Vector3
.
up
,
Vector2
.
right
,
ropeDistance
,
ropeLayer
);
RaycastHit2D
hit4
=
Physics2D
.
Raycast
(
transform
.
position
-
ropeDown
*
Vector3
.
up
,
Vector2
.
left
,
ropeDistance
,
ropeLayer
);
Debug
.
DrawRay
(
transform
.
position
+
ropeUp
*
Vector3
.
up
,
ropeDistance
*
Vector2
.
right
,
Color
.
red
);
Debug
.
DrawRay
(
transform
.
position
+
ropeUp
*
Vector3
.
up
,
ropeDistance
*
Vector2
.
left
,
Color
.
red
);
Debug
.
DrawRay
(
transform
.
position
-
ropeDown
*
Vector3
.
up
,
ropeDistance
*
Vector2
.
right
,
Color
.
red
);
Debug
.
DrawRay
(
transform
.
position
-
ropeDown
*
Vector3
.
up
,
ropeDistance
*
Vector2
.
left
,
Color
.
red
);
return
hit1
.
collider
!=
null
||
hit2
.
collider
!=
null
||
hit3
.
collider
!=
null
||
hit4
.
collider
!=
null
;
RaycastHit2D
hit
=
Physics2D
.
BoxCast
(
transform
.
position
+
new
Vector3
(
0
,
(
ropeUp
-
ropeDown
)
/
2f
),
new
Vector2
(
Player
.
X
,
ropeUp
+
ropeDown
),
0
,
Vector2
.
zero
,
0
,
ropeLayer
);
Debug
.
DrawLine
(
transform
.
position
+
new
Vector3
(-
Player
.
X
/
2f
,
ropeUp
,
0
),
transform
.
position
+
new
Vector3
(
Player
.
X
/
2f
,
ropeUp
,
0
));
Debug
.
DrawLine
(
transform
.
position
+
new
Vector3
(-
Player
.
X
/
2f
,
-
ropeDown
,
0
),
transform
.
position
+
new
Vector3
(
Player
.
X
/
2f
,
-
ropeDown
,
0
));
return
hit
.
collider
!=
null
;
}
bool
OnPlatform
()
{
RaycastHit2D
hit
=
Physics2D
.
BoxCast
(
transform
.
position
,
new
Vector2
(
Player
.
X
,
boxHeight
),
0
,
Vector2
.
down
,
Player
.
Y
/
2f
,
platformLayer
);
return
hit
.
collider
!=
null
&&
rb
.
velocity
.
y
==
0
;
// 플랫폼 점프 버그 방지
}
public
IEnumerator
DownPlatform
()
{
Physics2D
.
IgnoreCollision
(
platformCollider
,
transform
.
GetComponent
<
Collider2D
>(),
true
);
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
);
isDownPlatform
=
false
;
}
public
IEnumerator
RopeDelay
()
{
ropeEnabled
=
false
;
isJumpable
=
true
;
yield
return
new
WaitForSeconds
(
0.
5
f
);
yield
return
new
WaitForSeconds
(
0.
3
f
);
ropeEnabled
=
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