반응형

Physics.BoxCastAll  을 사용하다보면(또는 유사 다른 cast) point 값이 0,0,0 으로 

나오거나 또는 normal 값이 이상한 형태로 나오는 것을 볼 수 있는데 이 이유에 대해 살펴봅시다



Physics.BoxCastAll



public static RaycastHit[] BoxCastAll(Vector3 centerVector3 halfExtentsVector3 directionQuaternion orientation = Quaternion.identity, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);

Parameters

centerCenter of the box.
halfExtentsHalf the size of the box in each dimension.
directionThe direction in which to cast the box.
orientationRotation of the box.
maxDistanceThe max length of the cast.
layermaskLayer mask that is used to selectively ignore colliders when casting a capsule.
queryTriggerInteractionSpecifies whether this query should hit Triggers.

Returns

RaycastHit[] All colliders that were hit.

Description

Like Physics.BoxCast, but returns all hits.

Notes: For colliders that overlap the box at the start of the sweep, RaycastHit.normal is set opposite to the direction of the sweep, RaycastHit.distance is set to zero, and the zero vector gets returned in RaycastHit.point. You might want to check whether this is the case in your particular query and perform additional queries to refine the result.



박스 단위로 충돌을 검사하는 함수입니다 



유효한 충돌 범위는


(대상 오브젝트의 centerhalfExtents 위치 기준=)maxDistance  > 충돌 가능 범위 >  centerhalfExtents


.99 그이하 미소 범위[e] 에 대해선 소수점 오차로 인해 충돌 판별 되는 양상을 띕니다 




가정


Cast 보낼 오브젝트 위치 정보

pos   : 0,0,-30

scale : 10,10,10


대상 오브젝트 정보 [1]

pos   : 0,0,-5

scale : 10,10,10


maxDistance 15 


그외 정보는 일반적으로 unit 한 정보라 가정합니다(normal 은 당연히 시작 오브젝트에서 대상을 바라본다 가정 합니다)



위의 경우 충돌이 되지만 


대상 오브젝트가 [2]

pos   : 0,0,-4.5

scale : 10,10,10


인 경우에는 충돌되지 않습니다





계산



충돌 시작점 + half

centerhalfExtents 의 위치에서부터 maxDistance 이 계산 됨으로


 -30 + 15 + 5 = -10


즉 대상체의 충돌 검출 시작점은 -10 (충돌 가능 범위 기준) 이내 범위어야합니다



그리하여 (대상 오브젝트가 [2])

-4.5 - 5 = -9.5  의 범위에선 충돌되지 않지만


그리하여 (대상 오브젝트가 [1])

-5.0 - 5 = -10  의 범위에선 충돌 검출을 하게 됩니다



만약 충돌될 대상 오브젝트가 충돌 시작위치의 halfExtents 을 침범하게 된다면?





주의


은 출돌검사를 시작하는 center 위치에서 halfExtents 까지의 범위 안에 충돌체가 들어왔고 이 충돌체와 충돌 하게 되면 pint 값이 0 이 되며

normal 값은 sweep 의 방향에 반대되는 (- 가 곱해진) normal 을 만듭니다






ref : https://docs.unity3d.com/ScriptReference/Physics.BoxCastAll.html


반응형

+ Recent posts