Closed junhyungPARK78 closed 1 year ago
OnTriggerEnter2D()
넣어서 로그 찍히게 한 코드가 반응을 안해서 하루 동안 끙끙댐.
알고보니 패들에 연결한 스크립트를 수정한게 아니고 예전 거 놔둔거를 만지고 있어서 반응이 없었던 거였음.
개삽질을...
제대로 패들에 연결되어 있는 스크립트를 수정하니 문제없이 로그 찍히는 거 확인함.
private void OnTriggerEnter2D(Collider2D other)
{
Debug.Log ($"ball Position.x : {other.transform.position.x}");
}
Vector2 myPos = gameObject.transform.position;
과 같이, gameObject
를 사용하면 된다.
참고 url https://dydvn.tistory.com/48
Vector2 parentPos = gameObject.transform.parent.transform.position;
private void OnCollisionEnter2D(Collision2D other)
{
Rigidbody2D ballRigidBody = other.collider.gameObject.GetComponent<Rigidbody2D>();
Collision2D.collider.gameObject
를 사용한다.
Vector2 inDirection = ballRigidBody.velocity; // 입사 벡터 (속도)
Vector2 inNormal = transform.up; // 노말 벡터
Vector2 result = Vector2.Reflect(inDirection, inNormal);
ballRigidBody.velocity = result;
입사각과 반사되는 기물의 각도를 조정하면 패들 위치에 따른 반사각을 조정할 수 있을 듯하다.
입사각을 transform.down
으로 고정하고 노말 벡터의 각도를 패들과 공의 접촉 위치에 따라 바꾸어주면 될 듯하다.
SceneManager.LoadScene
를 쓰래더라.
현재 열려있는 scene을 다시 열려면 :
Application.LoadLevel(Application.loadedLevel);
↓
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
Debug.Log (@$"
====== Ball과 Block 관련 Log 시작 ======
・Break Block
・ball Block Vector = {ballRigidBody.GetVector(other.transform.position)}
====== Log 종료 ======");
@""
를 사용한다.
$""
와 겸용도 가능하다. : @$""
의 방법으로.
Vector2 startVector = new Vector2(1f, 2f).normalized;
normalized
를 사용하면 같은 방향을 가리키면서 길이가 1인 단위 벡터를 자동으로 만들어 준다.
참고 url : https://fiftiesstudy.tistory.com/249
참고 url https://post.naver.com/viewer/postView.nhn?volumeNo=21636704&memberNo=1085064&searchKeyword=%EB%B2%BD%EB%8F%8C&searchRank=332