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
f970dda9
Commit
f970dda9
authored
Jan 07, 2019
by
abpo11
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
플레이어가 로프를 탈 수 있게됨. 로프에 닿은 상태에서 점프시 타고, 좌우 방향키만 누를시 내림
parent
c58083ac
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
26 deletions
+75
-26
PlayScene.unity
Assets/Scenes/PlayScene.unity
+5
-0
PlayerController.cs
Assets/Scripts/Characters/PlayerController.cs
+70
-26
No files found.
Assets/Scenes/PlayScene.unity
View file @
f970dda9
...
...
@@ -393,10 +393,15 @@ MonoBehaviour:
speed
:
600
speedAir
:
5
jumpSpeed
:
400
ropeSpeed
:
200
doubleJumpSpeed
:
400
groundLayer
:
serializedVersion
:
2
m_Bits
:
256
ropeLayer
:
serializedVersion
:
2
m_Bits
:
512
ropeDistance
:
0.3
rayDistance
:
1
---
!u!212
&489222436
SpriteRenderer
:
...
...
Assets/Scripts/Characters/PlayerController.cs
View file @
f970dda9
...
...
@@ -2,7 +2,8 @@
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
PlayerController
:
MonoBehaviour
{
public
class
PlayerController
:
MonoBehaviour
{
private
Rigidbody2D
rb
;
// RigidBody2D of this game object
// Speeds of player
...
...
@@ -15,34 +16,42 @@ public class PlayerController : MonoBehaviour {
[
SerializeField
]
private
float
jumpSpeed
;
[
SerializeField
]
private
float
ropeSpeed
;
[
SerializeField
]
private
float
doubleJumpSpeed
;
// Bool values for jump & doublejump
private
bool
isGrounded
=
true
;
private
bool
isJumpable
=
true
;
// Can player jump or doublejump?
private
bool
isInRope
=
false
;
// Inputs
private
float
horizontal
=
0
;
private
float
horizontalRaw
=
0
;
private
float
verticalRaw
=
0
;
private
bool
jump
=
false
;
// Variables for IsGrounded()
[
SerializeField
]
private
LayerMask
groundLayer
;
[
SerializeField
]
private
LayerMask
ropeLayer
;
[
SerializeField
]
private
float
ropeDistance
=
0.3f
;
[
SerializeField
]
private
float
rayDistance
;
// Use this for initialization
void
Start
()
{
void
Start
()
{
rb
=
gameObject
.
GetComponent
<
Rigidbody2D
>();
}
// Update is called once per frame
void
Update
()
{
void
Update
()
{
horizontal
=
Input
.
GetAxis
(
"Horizontal"
);
horizontalRaw
=
Input
.
GetAxisRaw
(
"Horizontal"
);
verticalRaw
=
Input
.
GetAxisRaw
(
"Vertical"
);
if
(
Input
.
GetButtonDown
(
"Jump"
))
{
jump
=
true
;
...
...
@@ -55,32 +64,59 @@ public class PlayerController : MonoBehaviour {
if
(
isGrounded
)
isJumpable
=
true
;
if
(
IsInRope
())
{
if
(
isInRope
)
{
if
(
horizontalRaw
!=
0f
&&
verticalRaw
==
0f
)
{
isInRope
=
false
;
rb
.
gravityScale
=
2f
;
}
rb
.
velocity
=
new
Vector2
(
0f
,
verticalRaw
*
Time
.
smoothDeltaTime
*
ropeSpeed
);
}
else
if
(
jump
)
{
isInRope
=
true
;
rb
.
gravityScale
=
0f
;
transform
.
position
=
new
Vector2
(
Mathf
.
Round
(
transform
.
position
.
x
-
0.5f
)
+
0.5f
,
transform
.
position
.
y
);
rb
.
velocity
=
new
Vector2
(
0f
,
0f
);
}
}
else
{
isInRope
=
false
;
rb
.
gravityScale
=
2f
;
}
if
(!
isInRope
)
{
float
vertical
=
rb
.
velocity
.
y
;
if
(
jump
)
{
if
(
isGrounded
)
{
vertical
=
jumpSpeed
*
Time
.
fixed
DeltaTime
;
vertical
=
jumpSpeed
*
Time
.
smooth
DeltaTime
;
}
else
if
(
isJumpable
)
{
vertical
=
doubleJumpSpeed
*
Time
.
fixed
DeltaTime
;
vertical
=
doubleJumpSpeed
*
Time
.
smooth
DeltaTime
;
isJumpable
=
false
;
}
}
//rb.velocity = new Vector2(horizontal * speed *
Time.fixed
DeltaTime, vertical);
//rb.velocity = new Vector2(horizontal * speed *
Time.smooth
DeltaTime, vertical);
// rb.velocity = new Vector2(rb.velocity.x, vertical);
rb
.
AddForce
(
horizontalRaw
*
speed
*
Time
.
fixed
DeltaTime
*
Vector2
.
right
);
if
(((
horizontalRaw
==
0
)
||
(
rb
.
velocity
.
x
>
0
&&
horizontalRaw
<
0
)
||
(
rb
.
velocity
.
x
<
0
&&
horizontalRaw
>
0
))
&&(
isGrounded
))
rb
.
AddForce
(
horizontalRaw
*
speed
*
Time
.
smooth
DeltaTime
*
Vector2
.
right
);
if
(((
horizontalRaw
==
0
)
||
(
rb
.
velocity
.
x
>
0
&&
horizontalRaw
<
0
)
||
(
rb
.
velocity
.
x
<
0
&&
horizontalRaw
>
0
))
&&
(
isGrounded
))
{
rb
.
AddForce
(
rb
.
velocity
.
x
*
(-
10f
)
*
Vector2
.
right
);
}
rb
.
velocity
=
new
Vector2
(
Mathf
.
Clamp
(
rb
.
velocity
.
x
,
-
maxSpeed
*
Time
.
fixedDeltaTime
,
maxSpeed
*
Time
.
fixed
DeltaTime
),
vertical
);
rb
.
velocity
=
new
Vector2
(
Mathf
.
Clamp
(
rb
.
velocity
.
x
,
-
maxSpeed
*
Time
.
smoothDeltaTime
,
maxSpeed
*
Time
.
smooth
DeltaTime
),
vertical
);
}
jump
=
false
;
}
bool
IsGrounded
()
// Is player grounded?
...
...
@@ -89,4 +125,12 @@ public class PlayerController : MonoBehaviour {
Debug
.
DrawRay
(
transform
.
position
,
rayDistance
*
Vector2
.
down
,
Color
.
white
);
return
hit
.
collider
!=
null
;
}
bool
IsInRope
()
// Is player in rope?
{
RaycastHit2D
hit1
=
Physics2D
.
Raycast
(
transform
.
position
,
Vector2
.
right
,
ropeDistance
,
ropeLayer
);
RaycastHit2D
hit2
=
Physics2D
.
Raycast
(
transform
.
position
,
Vector2
.
left
,
ropeDistance
,
ropeLayer
);
Debug
.
DrawRay
(
transform
.
position
,
ropeDistance
*
Vector2
.
right
,
Color
.
red
);
Debug
.
DrawRay
(
transform
.
position
,
ropeDistance
*
Vector2
.
left
,
Color
.
red
);
return
hit1
.
collider
!=
null
||
hit2
.
collider
!=
null
;
}
}
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