Commit ba6bce1a authored by 18손재민's avatar 18손재민

Merge remote-tracking branch 'tetra-tower/ddd' into tetris

parents 538d6e4d bdef85c4
...@@ -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,37 +177,46 @@ MonoBehaviour: ...@@ -176,37 +177,46 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
rbGravityScale: 3 rbGravityScale: 3
rbAttackGravityScale: 3 rbAttackGravityScale: 0.5
maxSpeed: 3 maxSpeed: 4
maxDashSpeed: 6 maxDashSpeed: 7
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: 6400
ropeLayer: ropeLayer:
serializedVersion: 2 serializedVersion: 2
m_Bits: 512 m_Bits: 512
boxHeight: 0.3
ropeUp: 0.6
ropeDown: 0.8
platformLayer: platformLayer:
serializedVersion: 2 serializedVersion: 2
m_Bits: 2048 m_Bits: 2048
outerwallLayer:
serializedVersion: 2
m_Bits: 4096
ropeDistance: 0.3
rayDistance: 1
ropeUp: 0.6
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 +228,13 @@ MonoBehaviour: ...@@ -218,13 +228,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}
......
...@@ -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,30 +35,24 @@ public class PlayerController : MonoBehaviour ...@@ -35,30 +35,24 @@ 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 downKeyDown = false;
private bool jump = false; private bool jump = false;
[SerializeField] private bool dash = false;
private int dashStart = 0; // Variables for collsiion checking
// Variables for IsGrounded()
[SerializeField] [SerializeField]
private LayerMask groundLayer; private LayerMask groundLayer;
[SerializeField] [SerializeField]
private LayerMask ropeLayer; private LayerMask ropeLayer;
[SerializeField] [SerializeField]
private LayerMask platformLayer; private float boxHeight;
[SerializeField]
private LayerMask outerwallLayer;
[SerializeField]
private float ropeDistance = 0.3f;
[SerializeField]
private float rayDistance;
[SerializeField] [SerializeField]
private float ropeUp, ropeDown; private float ropeUp, ropeDown;
[SerializeField]
private LayerMask platformLayer;
public PlayerState playerState, previousState; public PlayerState playerState, previousState;
...@@ -70,9 +64,14 @@ public class PlayerController : MonoBehaviour ...@@ -70,9 +64,14 @@ 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");
if (isGrounded) dash = Input.GetButton("Dash");
if (!upKeyDown) upKeyDown = previous <= 0 && verticalRaw > 0;
if (!downKeyDown) downKeyDown = previous >= 0 && verticalRaw < 0;
if (Input.GetButtonDown("Jump")) if (Input.GetButtonDown("Jump"))
{ {
...@@ -98,122 +97,97 @@ public class PlayerController : MonoBehaviour ...@@ -98,122 +97,97 @@ 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 (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())
{ {
if (playerState == PlayerState.Rope) if (playerState == PlayerState.Rope)
{ {
if (horizontalRaw != 0f && verticalRaw == 0f) // Jump or Horizontal move in rope
if (jump || horizontal != 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 && horizontalRaw == 0) else if (verticalRaw != 0 && ropeEnabled && horizontal == 0)
{ {
playerState = PlayerState.Rope; playerState = PlayerState.Rope;
rb.gravityScale = 0f; 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) float direction = Mathf.Sign(xVelocity);
{ xVelocity = Mathf.Abs(xVelocity) - deceleration * airResistance * Time.fixedDeltaTime;
//짧게 눌렀을 때 if (xVelocity < 0) xVelocity = 0;
dashStart = 1; xVelocity *= direction;
} if (isGrounded) playerState = PlayerState.Idle;
} }
if (horizontalRaw == 0 && horizontal != 0 && dashStart == 1) else if (dash)
{ {
//방금 뗐을때 xVelocity += Mathf.Sign(horizontal) * dashAcceleration * airResistance * Time.fixedDeltaTime;
dashStart = 2; 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 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,47 +204,43 @@ public class PlayerController : MonoBehaviour ...@@ -230,47 +204,43 @@ public class PlayerController : MonoBehaviour
previousState = playerState; previousState = playerState;
} }
upKeyDown = false;
downKeyDown = false;
jump = false; jump = false;
} }
bool IsGrounded() // Is player grounded? bool IsGrounded() // Is player grounded?
{ {
RaycastHit2D hit1 = Physics2D.Raycast(transform.position + new Vector3(Player.X/2f, 0, 0), Vector2.down, rayDistance, groundLayer); RaycastHit2D hit = Physics2D.BoxCast(transform.position, new Vector2(Player.X, boxHeight), 0, Vector2.down, Player.Y / 2f, groundLayer);
RaycastHit2D hit2 = Physics2D.Raycast(transform.position + new Vector3(Player.X/2f, 0, 0), Vector2.down, rayDistance, platformLayer); Debug.DrawLine(transform.position + new Vector3(0, -Player.Y / 2f) + new Vector3(-Player.X, -boxHeight, 0) / 2,
RaycastHit2D hit3 = Physics2D.Raycast(transform.position + new Vector3(Player.X/2f, 0, 0), Vector2.down, rayDistance, outerwallLayer); transform.position + new Vector3(0, -Player.Y / 2f) + new Vector3(Player.X, -boxHeight, 0) / 2);
RaycastHit2D hit4 = Physics2D.Raycast(transform.position - new Vector3(Player.X/2f, 0,0), Vector2.down, rayDistance, groundLayer); return hit.collider != null && rb.velocity.y == 0; // 플랫폼 점프 버그 방지
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;//플랫폼 점프 버그 방지
} }
bool IsInRope() // Is player in rope? bool IsInRope() // Is player in rope?
{ {
RaycastHit2D hit1 = Physics2D.Raycast(transform.position + ropeUp * Vector3.up, Vector2.right, ropeDistance, ropeLayer); RaycastHit2D hit = Physics2D.BoxCast(transform.position + new Vector3(0, (ropeUp - ropeDown) / 2f), new Vector2(Player.X, ropeUp + ropeDown), 0, Vector2.zero, 0, ropeLayer);
RaycastHit2D hit2 = Physics2D.Raycast(transform.position + ropeUp * Vector3.up, Vector2.left, ropeDistance, ropeLayer); Debug.DrawLine(transform.position + new Vector3(-Player.X / 2f, ropeUp, 0),
RaycastHit2D hit3 = Physics2D.Raycast(transform.position - ropeDown * Vector3.up, Vector2.right, ropeDistance, ropeLayer); transform.position + new Vector3(Player.X / 2f, ropeUp, 0));
RaycastHit2D hit4 = Physics2D.Raycast(transform.position - ropeDown * Vector3.up, Vector2.left, ropeDistance, ropeLayer); Debug.DrawLine(transform.position + new Vector3(-Player.X / 2f, -ropeDown, 0),
Debug.DrawRay(transform.position + ropeUp * Vector3.up, ropeDistance * Vector2.right, Color.red); transform.position + new Vector3(Player.X / 2f, -ropeDown, 0));
Debug.DrawRay(transform.position + ropeUp * Vector3.up, ropeDistance * Vector2.left, Color.red); return hit.collider != null;
Debug.DrawRay(transform.position - ropeDown * Vector3.up, ropeDistance * Vector2.right, Color.red); }
Debug.DrawRay(transform.position - ropeDown * Vector3.up, ropeDistance * Vector2.left, Color.red); bool OnPlatform()
return hit1.collider != null || hit2.collider != null || hit3.collider != null || hit4.collider != null; {
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 new WaitForSeconds(0.1f); 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()
{ {
ropeEnabled = false; ropeEnabled = false;
isJumpable = true; isJumpable = true;
yield return new WaitForSeconds(0.5f); 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