Skip to content

RayCast Debug #9

@wogns0197

Description

@wogns0197

카메라 및 특정 오브젝트에서 나오는 터치판정 및 pre충돌판정에 있어서 가상의 Ray를 실제로 볼 수 있게 그려주는 기능입니다.
3D 작업을 할때 터치 판정 디버깅을 하려고 사용했습니다.

public class RayCaster : MonoBehaviour {
 
    void OnDrawGizmos() {
 
        float maxDistance = 100;
        RaycastHit hit;
        // Physics.Raycast (레이저를 발사할 위치, 발사 방향, 충돌 결과, 최대 거리)
        bool isHit = Physics.Raycast (transform.position, transform.forward, out hit, maxDistance);
 
        Gizmos.color = Color.red;
        if (isHit) {
            Gizmos.DrawRay (transform.position, transform.forward * hit.distance);
        } else {
            Gizmos.DrawRay (transform.position, transform.forward * maxDistance);
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions