Commit 2b006a73 authored by 16도재형's avatar 16도재형 Committed by 18류지석

플랫폼 위에 있을때만 아래로 뛸수있게 함 지석이가 점프해서 달리기 안되게하라고함

parent 417aca7a
...@@ -178,8 +178,8 @@ MonoBehaviour: ...@@ -178,8 +178,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
rbGravityScale: 3 rbGravityScale: 3
rbAttackGravityScale: 0.5 rbAttackGravityScale: 0.5
maxSpeed: 3 maxSpeed: 4
maxDashSpeed: 6 maxDashSpeed: 7
acceleration: 20 acceleration: 20
deceleration: 20 deceleration: 20
jumpSpeed: 11 jumpSpeed: 11
...@@ -196,6 +196,9 @@ MonoBehaviour: ...@@ -196,6 +196,9 @@ MonoBehaviour:
boxHeight: 0.3 boxHeight: 0.3
ropeUp: 0.6 ropeUp: 0.6
ropeDown: 0.8 ropeDown: 0.8
platformLayer:
serializedVersion: 2
m_Bits: 2048
playerState: 0 playerState: 0
previousState: 0 previousState: 0
--- !u!114 &114402380471012178 --- !u!114 &114402380471012178
......
...@@ -39,9 +39,10 @@ public class PlayerController : MonoBehaviour ...@@ -39,9 +39,10 @@ public class PlayerController : MonoBehaviour
private float horizontalRaw = 0; private float horizontalRaw = 0;
private float verticalRaw = 0; private float verticalRaw = 0;
private bool upKeyDown = false; private bool upKeyDown = false;
private bool downKeyDown = false;
private bool jump = false; private bool jump = false;
private bool dash = false; private bool dash = false;
// Variables for IsGrounded() // Variables for collsiion checking
[SerializeField] [SerializeField]
private LayerMask groundLayer; private LayerMask groundLayer;
[SerializeField] [SerializeField]
...@@ -50,7 +51,8 @@ public class PlayerController : MonoBehaviour ...@@ -50,7 +51,8 @@ public class PlayerController : MonoBehaviour
private float boxHeight; private float boxHeight;
[SerializeField] [SerializeField]
private float ropeUp, ropeDown; private float ropeUp, ropeDown;
[SerializeField]
private LayerMask platformLayer;
public PlayerState playerState, previousState; public PlayerState playerState, previousState;
...@@ -69,6 +71,7 @@ public class PlayerController : MonoBehaviour ...@@ -69,6 +71,7 @@ public class PlayerController : MonoBehaviour
dash = Input.GetButton("Dash"); dash = Input.GetButton("Dash");
if (!upKeyDown) upKeyDown = previous <= 0 && verticalRaw > 0; if (!upKeyDown) upKeyDown = previous <= 0 && verticalRaw > 0;
if (!downKeyDown) downKeyDown = previous >= 0 && verticalRaw < 0;
if (Input.GetButtonDown("Jump")) if (Input.GetButtonDown("Jump"))
{ {
...@@ -99,11 +102,10 @@ public class PlayerController : MonoBehaviour ...@@ -99,11 +102,10 @@ public class PlayerController : MonoBehaviour
} }
// Platform downjump // Platform downjump
if (verticalRaw < 0 && !isDownPlatform) if (OnPlatform() && downKeyDown)
{ {
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>();
isDownPlatform = true;
StartCoroutine(DownPlatform()); StartCoroutine(DownPlatform());
} }
if (IsInRope()) if (IsInRope())
...@@ -111,7 +113,7 @@ public class PlayerController : MonoBehaviour ...@@ -111,7 +113,7 @@ public class PlayerController : MonoBehaviour
if (playerState == PlayerState.Rope) if (playerState == PlayerState.Rope)
{ {
// Jump or Horizontal move in rope // Jump or Horizontal move in rope
if (jump || (horizontal != 0 && verticalRaw == 0)) if (jump || horizontal != 0)
{ {
playerState = PlayerState.Idle; playerState = PlayerState.Idle;
rb.gravityScale = rbGravityScale; rb.gravityScale = rbGravityScale;
...@@ -203,6 +205,7 @@ public class PlayerController : MonoBehaviour ...@@ -203,6 +205,7 @@ public class PlayerController : MonoBehaviour
} }
upKeyDown = false; upKeyDown = false;
downKeyDown = false;
jump = false; jump = false;
} }
bool IsGrounded() // Is player grounded? bool IsGrounded() // Is player grounded?
...@@ -221,13 +224,17 @@ public class PlayerController : MonoBehaviour ...@@ -221,13 +224,17 @@ public class PlayerController : MonoBehaviour
transform.position + new Vector3(Player.X / 2f, -ropeDown, 0)); transform.position + new Vector3(Player.X / 2f, -ropeDown, 0));
return hit.collider != null; 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() public IEnumerator DownPlatform()
{ {
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 null; while (playerState == PlayerState.Rope) yield return null;
Physics2D.IgnoreCollision(platformCollider, transform.GetComponent<Collider2D>(), false); Physics2D.IgnoreCollision(platformCollider, transform.GetComponent<Collider2D>(), false);
isDownPlatform = false;
} }
public IEnumerator RopeDelay() public IEnumerator RopeDelay()
{ {
...@@ -235,7 +242,5 @@ public class PlayerController : MonoBehaviour ...@@ -235,7 +242,5 @@ public class PlayerController : MonoBehaviour
isJumpable = true; isJumpable = true;
yield return new WaitForSeconds(0.3f); yield return new WaitForSeconds(0.3f);
ropeEnabled = true; ropeEnabled = true;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment