Today I Learn/내일배움캠프

Unity 게임 개발 입문 - 팀프로젝트 (5주차 4일)

오늘도즐겨 2024. 10. 18. 23:37

🔥 10/18 금요일 목표 🔥

🔎 벽돌깨기게임 볼 구현 및 기본 세팅하기

🔎 수준별 꾸준실습 제출하기

 

 10:00 팀프로젝트진행 

 12:00 수준별 꾸준 실습 

 

⭐️ Paddle Moving값 제어하기

 

curPos.x를 수정한 후 그 값을 다시 transform.position에 적용함으로써,
제한된 x 값이 실제로 반영되도록 하였습니다.

private void Moving()
{
    Vector3 curPos = transform.position;

    //= curPos.x = Mathf.Clamp(curPos.x , 2f, 2f) 동일
	if (curPos.x < -2f)
	{
    	curPos.x = -2f;
	}
	else if (curPos.x > 2f)
	{
   		curPos.x = 2f;
	}
    transform.position = curPos;
    transform.Translate(input.dir * speed * Time.deltaTime, 0, 0);
}

 

⭐️ Ball구현하기

입사각 - 반사각

private float ballSpeed = 5f;
private Vector2 ballDir;
private bool isTouched;
private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.tag == "Wall")
    {
        ballDir = Vector2.Reflect(ballDir, collision.contacts[0].normal);
    }
    else if (collision.gameObject.tag == "Player")
    {
        // 기본 방향 계산
        ballDir = Vector2.Reflect(ballDir, collision.contacts[0].normal);

        // 약간의 각도 변화가 발생 -15도에서 15도 사이로 변경
        // collision.contacts[0].point.x

        if (collision.contacts[0].point.x < playerPaddle.transform.position.x)
        {
            float angleOffsetLeft = Random.Range(-30f, 0f);
            ballDir = Quaternion.Euler(0, 0, angleOffsetLeft) * ballDir;
        }
        else if (collision.contacts[0].point.x > playerPaddle.transform.position.x)
        {
            float angleOffsetRight = Random.Range(0f, 30f);
            ballDir = Quaternion.Euler(0, 0, angleOffsetRight) * ballDir;
        }
    }
}
private void Start()
{
    ballDir = Vector2.up.normalized;
}
void Update()
{
    if (isTouched)
    {
        Vector3 playerPaddlePos = GameObject.Find("PlayerPaddle").transform.position;

        Vector3 ballPos = playerPaddlePos;
        ballPos.y += 0.1f;
        transform.position = ballPos;
    }
    else
    {
        transform.Translate(ballDir * ballSpeed * Time.deltaTime);
    }
}

 

 

🔥 10/19 - 20 주말 목표 🔥 

🔎 벽돌깨기게임  - UI 찾아보기

 

🔥 10/21 월요일 목표 🔥 

🔎  베스트 스코어 저장하기

🔎 남은 프로젝트 진행 및 PPT완성하기