Skip to content

RayCast Debug #9

Open
Open

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);
        }
    }
}

Activity

  1. ggjae commented on Jul 26, 2021

    @ggjae
    Member

    어렵네요... 오랜만에 다시 ray에 대해 일깨워주셔서 감사합니다. 혹시 3차원이 아닌 2차원에서도 ray를 많이 사용하나요? 한번 기회가 된다면 재훈님께서 Ray를 사용하는 적절한 예시나 지금까지 했던 프로젝트에서 어떨 때에 ray를 사용했더니 좋았다 등의 실전 Ray 사용법에 대해서 공유해주신다면 정말 Issue에 길이길이 남을만한 좋은 Issue일 것 같습니다 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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