using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
[SerializeField] private float jumpForce;
[Range(0, .3f)] [SerializeField] private float m_MovementSmoothing = .05f;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask whatIsGround;
[SerializeField] private Animator animator;
const float checkRadius = 0.1f;
private float moveInput;
private Rigidbody2D rb;
private bool facingRight = true;
private bool isGrounded = false;
private bool jump = false;
private int extraJumps = 1;
private Vector3 refVelocity = Vector3.zero;
bool isCheck;
void Start()
{
rb = GetComponent<Rigidbody2D>();
isCheck = true;
}
void FixedUpdate()
{
if (isCheck)
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(groundCheck.position, checkRadius, whatIsGround);
for (int i = 0; i < colliders.Length; i++)
{
if (colliders[i].gameObject != gameObject)
{
Debug.Log(colliders[i].gameObject.name);
isGrounded = true;
animator.SetBool("Jump", false);
animator.SetBool("Jump2", false);
jump = false;
}
}
}
moveInput = Input.GetAxisRaw("Horizontal");
Vector3 targetVelocity = new Vector3(moveInput * speed * Time.fixedDeltaTime, rb.velocity.y);
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref refVelocity, m_MovementSmoothing);
if (jump == false)
{
animator.SetFloat("Speed", Mathf.Abs(moveInput) * speed);
}
if (facingRight == false && moveInput > 0)
{
Flip();
}
else if (facingRight == true && moveInput < 0)
{
Flip();
}
}
void Update()
{
if (isGrounded == true)
{
extraJumps = 2;
}
if (Input.GetButtonDown("Jump") && extraJumps == 2)
{
Jump();
}else if (Input.GetButtonDown("Jump") && extraJumps == 1)
{
Jump();
}
}
IEnumerator Jump_()
{
extraJumps--;
isCheck = false;
if (extraJumps == 1)
{
animator.SetBool("Jump", true);
}
if (extraJumps == 0)
{
animator.SetBool("Jump2", true);
}
jump = true;
isGrounded = false;
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
yield return new WaitForSeconds(0.1f);
isCheck = true;
}
void Jump()
{
StartCoroutine("Jump_");
}
void Flip()
{
facingRight = !facingRight;
Vector2 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
점프가 왜 안됐냐 하니까 저 그라운드 체크가 바로 이어져있어서 점프하자마자 점프를 페일 시켜버리더라 그래서 첫번째는 안되고 두번째는 점프모션 나오던거 ....
2단 점프라서 점프 모션 하나 더 복제해서 셋불 jump2 라고 따로 하나 만들었다 애니메이터 연결은 player_jump에서 player_Jump2 로 jump2 를 연결해주고
player_Jump2 에서 Player_Idle 로 jump false 연결 해주고 player_Jump2에서 Player_Run 으로 jump false 랑 speed greate 0.01 연결해줬당 ㅇㅇ
그리고 jump 랑 jump2 에서 player_Idle 로 연결되는부분에 speed less 0.01 이건 때버렸다 ㅇㅇ
그리고 케릭터 밑으로 빠진다는건.... 난 안빠지고 잘 되더라 ????
그래서 그건 수정 못했음 ㅇㅇ
암튼 그럼 즐뎁 수공!
움짤은 클릭해야 움직임
와 너 혹시 천사냐 진짜 개고맙다 와우아ㅜㅏ아아아ㅏㅏ 사랑해 혹시나 해서 올렷는데 진짜 고쳐줄줄은 몰랏엉 우아ㅏ아아ㅏㅏ 고맙다 진짜 방명록에 글은 지저분할거같으니 지워놓을게
ㄴ서로 돕고사는거지 뭐 ㅇㅇ/ 화이팅!
내가 이거때문에 일주일동안 시간 낭비했거덩 ㅠ 보이지도 않는거 계속 찾아본다고 시간 어지간히 버렸는데.. 일단 패스하고 딴거로 넘어갈까 할 때 니가 딱 나타남 오오 구세주여
ㄴ너무 띄워주면 날아감 ㅇㅇ/ 즐뎁!
저기, 미안한데 혹시 isCheck은 뭐 확인하는 변수인지 알 수 있어?
이즈체크가 바닥 확인하는걸 잠깐 멈추게 하는거야 코루틴들어갈때 펄스 시키고 0.1초 후에 트루 시켜서 다시 바닥 체크하게 한거 ㅇㅇ//