Commit 78d115be authored by abpo11's avatar abpo11

로프 조작감 고침. 로프에서 스스로 내리면 다시 탈 때까지 0.5초의 딜레이, 다시 점프 가능

플랫폼 만듬. 아래 방향키로 내려갈 수 있음.
방을 클리어했다면 방 밖이 보이게 카메라 수정
방향키를 빠르게 연타하면 대쉬를 할 수 있음.
기타 이동 관련 조작감 수정함.
parent 58e64dab
...@@ -253,20 +253,35 @@ MonoBehaviour: ...@@ -253,20 +253,35 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f289cad4933d4bf42ae5c82c57bd88e4, type: 3} m_Script: {fileID: 11500000, guid: f289cad4933d4bf42ae5c82c57bd88e4, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
maxSpeed: 400 maxSpeed: 300
speed: 600 speed: 600
speedAir: 5 speedAir: 5
jumpSpeed: 400 jumpSpeed: 400
ropeSpeed: 200 ropeSpeed: 200
doubleJumpSpeed: 400 doubleJumpSpeed: 400
dashSpeed: 1000
dashDelay: 0
isDashing: 0
platformArray: []
horizontal: 0
horizontalRaw: 0
dashStart: 0
groundLayer: groundLayer:
serializedVersion: 2 serializedVersion: 2
m_Bits: 256 m_Bits: 256
ropeLayer: ropeLayer:
serializedVersion: 2 serializedVersion: 2
m_Bits: 512 m_Bits: 512
platformLayer:
serializedVersion: 2
m_Bits: 2048
outerwallLayer:
serializedVersion: 2
m_Bits: 4096
ropeDistance: 0.3 ropeDistance: 0.3
rayDistance: 1 rayDistance: 1
ropeUp: 0.5
ropeDown: 0.5
--- !u!212 &489222436 --- !u!212 &489222436
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -364,6 +379,7 @@ MonoBehaviour: ...@@ -364,6 +379,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
LCUI: {fileID: 0} LCUI: {fileID: 0}
ttx: 0 ttx: 0
tty: 0
--- !u!1001 &695959412 --- !u!1001 &695959412
Prefab: Prefab:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -68,42 +68,52 @@ public class CameraController : MonoBehaviour { ...@@ -68,42 +68,52 @@ public class CameraController : MonoBehaviour {
{ {
float posx = player.transform.position.x; float posx = player.transform.position.x;
float posy = player.transform.position.y; float posy = player.transform.position.y;
if (RoomCol(1) != -1)
{ Room curRoom = MapManager.mapGrid[Player.tx, Player.ty];
posy = RoomCol(1) - camY; if (!curRoom.GetComponentInChildren<RoomInGame>().isRoomClear)
}
if (RoomCol(2) != -1)
{
posy = RoomCol(2) + camY;
}
if (RoomCol(3) != -1)
{
posx = RoomCol(3) + camX;
}
if (RoomCol(4) != -1)
{
posx = RoomCol(4) - camX;
}
if (RoomCol(3) != -1 && RoomCol(4) != -1)
{
float middle = Player.tx * 24f + 12f;
if (middle - RoomCol(3) > 20f)
{
posx = RoomCol(3) + camX;
}
else if (RoomCol(4) - middle > 20f)
{
posx = RoomCol(4) - camX;
}
else
{ {
posx = player.transform.position.x;
if (RoomCol(1) != -1)
{
posy = RoomCol(1) - camY;
}
if (RoomCol(2) != -1)
{
posy = RoomCol(2) + camY;
}
if (RoomCol(3) != -1)
{
posx = RoomCol(3) + camX;
}
if (RoomCol(4) != -1)
{
posx = RoomCol(4) - camX;
}
if (RoomCol(3) != -1 && RoomCol(4) != -1)
{
float middle = Player.tx * 24f + 12f;
if (middle - RoomCol(3) > 20f)
{
posx = RoomCol(3) + camX;
}
else if (RoomCol(4) - middle > 20f)
{
posx = RoomCol(4) - camX;
}
else
{
posx = player.transform.position.x;
}
//방의 중심과 비교하여 어느게 더 가까운가
}
} }
//방의 중심과 비교하여 어느게 더 가까운가
}
transform.position = Vector3.Lerp(transform.position, new Vector3(posx, posy, 0), 2f * Time.deltaTime);
transform.position = Vector3.Lerp(transform.position, new Vector3(posx, posy, 0), 2f * Time.deltaTime); transform.position = new Vector3(transform.position.x, transform.position.y, -1); //카메라를 원래 z축으로 이동
transform.position = new Vector3(transform.position.x, transform.position.y, -1); //카메라를 원래 z축으로 이동
} }
// Camera.main.transform.position = new Vector3(posx, posy, -10); // Camera.main.transform.position = new Vector3(posx, posy, -10);
......
...@@ -6,6 +6,7 @@ public class Player : MonoBehaviour { ...@@ -6,6 +6,7 @@ public class Player : MonoBehaviour {
public LifeCrystalUI LCUI; public LifeCrystalUI LCUI;
public static int tx, ty; public static int tx, ty;
public int ttx; public int ttx;
public int tty;
// Use this for initialization // Use this for initialization
void Start () { void Start () {
...@@ -15,6 +16,8 @@ public class Player : MonoBehaviour { ...@@ -15,6 +16,8 @@ public class Player : MonoBehaviour {
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
tx = (int)(transform.position.x / 24f); tx = (int)(transform.position.x / 24f);
ty = (int)(transform.position.y / 24f);
ttx = tx; ttx = tx;
tty = ty;
} }
} }
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Tilemaps;
public class PlayerController : MonoBehaviour public class PlayerController : MonoBehaviour
{ {
...@@ -19,27 +20,43 @@ public class PlayerController : MonoBehaviour ...@@ -19,27 +20,43 @@ public class PlayerController : MonoBehaviour
private float ropeSpeed; private float ropeSpeed;
[SerializeField] [SerializeField]
private float doubleJumpSpeed; private float doubleJumpSpeed;
[SerializeField]
private float dashSpeed;
[SerializeField]
private float dashDelay;
[SerializeField]
private bool isDashing = false;
public TilemapCollider2D[] platformArray;
// Bool values for jump & doublejump // Bool values for jump & doublejump
private bool isGrounded = true; private bool isGrounded = true;
private bool isJumpable = true; // Can player jump or doublejump? private bool isJumpable = true; // Can player jump or doublejump?
private bool isInRope = false; private bool isInRope = false;
private bool isDownPlatform = false;
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 jump = false; private bool jump = false;
[SerializeField]
private int dashStart = 0;
// Variables for IsGrounded() // Variables for IsGrounded()
[SerializeField] [SerializeField]
private LayerMask groundLayer; private LayerMask groundLayer;
[SerializeField] [SerializeField]
private LayerMask ropeLayer; private LayerMask ropeLayer;
[SerializeField] [SerializeField]
private LayerMask platformLayer;
[SerializeField]
private LayerMask outerwallLayer;
[SerializeField]
private float ropeDistance = 0.3f; private float ropeDistance = 0.3f;
[SerializeField] [SerializeField]
private float rayDistance; private float rayDistance;
[SerializeField]
private float ropeUp, ropeDown;
// Use this for initialization // Use this for initialization
void Start() void Start()
{ {
...@@ -52,6 +69,7 @@ public class PlayerController : MonoBehaviour ...@@ -52,6 +69,7 @@ public class PlayerController : MonoBehaviour
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 (Input.GetButtonDown("Jump")) if (Input.GetButtonDown("Jump"))
{ {
jump = true; jump = true;
...@@ -63,6 +81,13 @@ public class PlayerController : MonoBehaviour ...@@ -63,6 +81,13 @@ public class PlayerController : MonoBehaviour
isGrounded = IsGrounded(); isGrounded = IsGrounded();
if (isGrounded) if (isGrounded)
isJumpable = true; isJumpable = true;
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 (IsInRope()) if (IsInRope())
{ {
...@@ -72,11 +97,13 @@ public class PlayerController : MonoBehaviour ...@@ -72,11 +97,13 @@ public class PlayerController : MonoBehaviour
{ {
isInRope = false; isInRope = false;
rb.gravityScale = 2f; rb.gravityScale = 2f;
} StartCoroutine(RopeDelay());
}
rb.velocity = new Vector2(0f, verticalRaw * Time.smoothDeltaTime * ropeSpeed); rb.velocity = new Vector2(0f, verticalRaw * Time.smoothDeltaTime * ropeSpeed);
} }
else if (jump) else if (verticalRaw != 0 && ropeEnabled)
{ {
isInRope = true; isInRope = true;
rb.gravityScale = 0f; rb.gravityScale = 0f;
...@@ -104,10 +131,51 @@ public class PlayerController : MonoBehaviour ...@@ -104,10 +131,51 @@ public class PlayerController : MonoBehaviour
isJumpable = false; isJumpable = false;
} }
} }
if(verticalRaw == -1 && !isDownPlatform)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, platformLayer);
if (hit.collider != null && rb.velocity.y == 0)
{
Room curRoom = MapManager.mapGrid[Player.tx, Player.ty];
platformArray = curRoom.GetComponentsInChildren<TilemapCollider2D>();
isDownPlatform = true;
StartCoroutine(DownPlatform());
}
}
//rb.velocity = new Vector2(horizontal * speed * Time.smoothDeltaTime, vertical); //rb.velocity = new Vector2(horizontal * speed * Time.smoothDeltaTime, vertical);
// rb.velocity = new Vector2(rb.velocity.x, vertical); // rb.velocity = new Vector2(rb.velocity.x, vertical);
if(horizontalRaw != 0)
{
if(horizontal != 1 && horizontal != -1 && dashStart == 0)
{
//짧게 눌렀을 때
dashStart = 1;
}
}
if(horizontalRaw == 0 && horizontal != 0 && dashStart == 1)
{
//방금 뗐을때
dashStart = 2;
//이제 빠르게 켜면 됨
}
if(dashStart == 2 && horizontalRaw != 0)
{
isDashing = true;
}
if(horizontalRaw == 0 && horizontal == 0)
{
dashStart = 0;
isDashing = false;
}
if(isDashing)
rb.AddForce(horizontalRaw * dashSpeed * Time.smoothDeltaTime * Vector2.right);
else
rb.AddForce(horizontalRaw * speed * Time.smoothDeltaTime * Vector2.right); rb.AddForce(horizontalRaw * speed * Time.smoothDeltaTime * Vector2.right);
if (((horizontalRaw == 0) || (rb.velocity.x > 0 && horizontalRaw < 0) if (((horizontalRaw == 0) || (rb.velocity.x > 0 && horizontalRaw < 0)
|| (rb.velocity.x < 0 && horizontalRaw > 0)) && (isGrounded)) || (rb.velocity.x < 0 && horizontalRaw > 0)) && (isGrounded))
{ {
...@@ -115,22 +183,43 @@ public class PlayerController : MonoBehaviour ...@@ -115,22 +183,43 @@ public class PlayerController : MonoBehaviour
rb.AddForce(rb.velocity.x * (-10f) * Vector2.right); rb.AddForce(rb.velocity.x * (-10f) * Vector2.right);
} }
rb.velocity = new Vector2(Mathf.Clamp(rb.velocity.x, -maxSpeed * Time.smoothDeltaTime, maxSpeed * Time.smoothDeltaTime), vertical); rb.velocity = new Vector2(Mathf.Clamp(rb.velocity.x, -maxSpeed* (isDashing?1.5f:1f) * Time.smoothDeltaTime, maxSpeed*(isDashing ? 1.5f : 1f) * Time.smoothDeltaTime), vertical);
} }
jump = false; jump = false;
} }
bool IsGrounded() // Is player grounded? bool IsGrounded() // Is player grounded?
{ {
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, groundLayer); RaycastHit2D hit1 = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, groundLayer);
RaycastHit2D hit2 = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, platformLayer);
RaycastHit2D hit3 = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, outerwallLayer);
Debug.DrawRay(transform.position, rayDistance * Vector2.down, Color.white); Debug.DrawRay(transform.position, rayDistance * Vector2.down, Color.white);
return hit.collider != null; return (hit1.collider != null || hit2.collider != null || hit3.collider != null) && rb.velocity.y == 0 ;//플랫폼 점프 버그 방지
} }
bool IsInRope() // Is player in rope? bool IsInRope() // Is player in rope?
{ {
RaycastHit2D hit1 = Physics2D.Raycast(transform.position, Vector2.right, ropeDistance, ropeLayer); RaycastHit2D hit1 = Physics2D.Raycast(transform.position + ropeUp*Vector3.up, Vector2.right, ropeDistance, ropeLayer);
RaycastHit2D hit2 = Physics2D.Raycast(transform.position, Vector2.left, ropeDistance, ropeLayer); RaycastHit2D hit2 = Physics2D.Raycast(transform.position + ropeUp*Vector3.up, Vector2.left, ropeDistance, ropeLayer);
Debug.DrawRay(transform.position, ropeDistance * Vector2.right, Color.red); RaycastHit2D hit3 = Physics2D.Raycast(transform.position - ropeDown * Vector3.up, Vector2.right, ropeDistance, ropeLayer);
Debug.DrawRay(transform.position, ropeDistance * Vector2.left, Color.red); RaycastHit2D hit4 = Physics2D.Raycast(transform.position - ropeDown * Vector3.up, Vector2.left, ropeDistance, ropeLayer);
return hit1.collider != null || hit2.collider != null; 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;
}
public IEnumerator DownPlatform()
{
platformArray[2].enabled = false;
yield return new WaitForSeconds(0.3f);
platformArray[2].enabled = true;
isDownPlatform = false;
}
public IEnumerator RopeDelay()
{
ropeEnabled = false;
isJumpable = true;
yield return new WaitForSeconds(0.5f);
ropeEnabled = true;
} }
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary> /// <summary>
/// Room class /// Room class
/// </summary> /// </summary>
......
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