반응형




[SphereCast ] : 광선을 따라 구를 캐스팅하고 무엇이 맞았는지에 대한 자세한 정보를 반환합니다.


Raycast가 충분한 정밀도를 제공하지 않을 때 유용합니다. 왜냐하면 캐릭터와 같은 특정 크기의 객체가 도중에 충돌하지 않고 어딘가로 이동할 수 있는지 알아 내려고하기 때문입니다. 두꺼운 레이 캐스트와 같은 캐스트를 생각해보십시오. 이 경우 광선은 시작 벡터와 방향으로 지정됩니다.





public static bool SphereCast(Vector3 origin, float radiusVector3 direction, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteractionqueryTriggerInteraction = QueryTriggerInteraction.UseGlobal);



Parameters

originThe center of the sphere at the start of the sweep.
radiusThe radius of the sphere.
directionThe direction into which to sweep the sphere.
hitInfoIf true is returned, hitInfo will contain more information about where the collider was hit. (See Also: RaycastHit).
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.






설명

구체를 씬 상의 모든 충돌체를 대상으로 발사하여 충돌한 것에 대한 자세한 정보를 반환합니다.

Raycast가 충분한 정밀도를 제공하지 않아 캐릭터와 같이 이동하는 길에 아무것도 충돌하지 않는 물체의 특정 크기를 알아내야 할때 이 함수가 유용할 수 있습니다. Sphere cast를 두꺼운 raycast라고 생각하십시오. 

선 대신 구를 던져서 캐스팅

"스윕" 설명

( 스윕 교차) : 어떤 물체를 치고 지나갈때 멈추게함을 말함 (https://www.unrealengine.com/ko/blog/moving-physical-objects)


[OverlapSphere]


지정한 위치로 부터 지정한 범위안에 접촉한 콜라이더 배열로 반환 (접촉 또는 범위안의 것들)


public static Collider[] OverlapSphere(Vector3 position, float radius, int layerMask = AllLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);


layerMask는 레이 캐스팅 시에 콜라이더를 선택적으로 무시하는데 사용





[사용]



using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void ExplosionDamage(Vector3 center, float radius) { Collider[] hitColliders = Physics.OverlapSphere(center, radius); int i = 0; while (i < hitColliders.Length) { hitColliders[i].SendMessage("AddDamage"); i++; } } }


Physics.OverlapSphere()

ex) Collider[] cols = Physics.OverlapSphere(tr.position(원점), 10.0f(반경));


반경내에 들어와 있는 GameObject를 검출

GameObject는 Collider컴포넌트가 추가돼 있어야 함.

반환값은 Collider 배열 형태로 반환.





http://sharkmino.tistory.com/1437

http://sellingout.blog.me/221033922714

https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html

http://www.devkorea.co.kr/reference/Documentation/ScriptReference/Physics.SphereCast.html


반응형

+ Recent posts