Unity_Basic #13

haechi·2021년 8월 24일
0

unity

목록 보기
36/39

210824
Unity_Basic #13


-Bounds

Bounds bounds = capsuleCollider2D.bounds;
footPosition = new Vector2(bounds.center.x, bounds.min.y);
isGrounded = Physics2D.OverlapCircle(footPosition, 0.1f, groundLayer);

-capsuleCollider2D.bounds라는 것이 무엇일까?
Bounds란 축 정렬된 경계상자(Axis Aligned Bounding Box)를 의미한다고 한다.
축 정렬된 경계상자(Axis Aligned Bounding Box), 또는 약자로 AABB 불리우는 이 상자는 좌표 축(Coordinate Axes)으로 정렬되어 있으며 특정 객체를 완벽히 둘러싸고 있습니다. 이는 상자가 전혀 축에 비례하여 회전하지 않기 때문이며, 상자의 center 와 extents값을 통해 간단히 정의되거나 또는 차선책으로 min 과 max 지점을 정의할 수 도 있습니다.

잘 모르겠다.

보면 변수로 center, size, extents, min, max 가 있다.
지금 코드에서는 capsuleCollider2D.bounds를 bounds로 받고 footPosition에 bounds.center.x, bounds.min.y를 받는다.

이같은 경계를 의미하는 듯 하다.
그렇다면 bounds의 center값의 x좌표와 bounds의 최소지점의 y좌표라는 의미니 collider의 발위치, 즉 바닥의 중간위치로 볼 수 있다.

isGrounded는 Physics2D.OverlapCircle()로 결정되는데 이 함수는 무엇일까.
Physics2D는 유니티에서 2D로 구성된 게임을 위해서 제공되는 물리를 위한 시뮬레이션 엔진이라고 한다. Physics2D에서 제공하는 메서드중 하나이다.
OverlapCircle()의 매개변수는 좌표(Point)로 Vectro2, 반지름를 나타내는 실수와 레이어 마스크를 나타내는 정수를 가진다.
OverlapCircle(Vector2 point, float radius, int layerMask)
그렇다면 위의 코드에서는 좌표는 오브젝트의 발 위치, 반지름, 레이어를 받는다.

이를 이용해서 isGrounded는 오버랩이 되면(레이어와), 즉 착지한 상태를 나타내게 되는 것이다.

참고
https://stackoverflow.com/questions/66360236/collider2d-bounds-explaination
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=pxkey&logNo=221324857701
http://www.devkorea.co.kr/reference/Documentation/ScriptReference/Bounds.html

profile
공부중인 것들 기록

0개의 댓글