Unity. Physics.SphereCast()
๐ Physics.SphereCast()
์ฐ์ํ๋ ๊ตฌ ์์ ์ถฉ๋์ฒด๋ฅผ ๋ฐํํ๋ค.
ํธ๋ฅธ ์ง์ ์ ์ถฉ๋์ฒด๋ฅผ ๋ฐํ
๐ ์ฌ์ฉ๋ฒ
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
CharacterController charCtrl;
void Start() {
charCtrl = GetComponent<CharacterController>();
}
void Update() {
RaycastHit hit;
Vector3 p1 = transform.position + charCtrl.center;
float distanceToObstacle = 0;
// Cast a sphere wrapping character controller 10 meters forward
// to see if it is about to hit anything.
if (Physics.SphereCast(p1, charCtrl.height / 2, transform.forward, out hit, 10)) {
distanceToObstacle = hit.distance;
}
}
}
์ ๋ํฐ ๊ณต์ ๋ฌธ์์์ ๋ค๊ณ ์๋ค. ์ธ์๋ ์์ ์ง์ ๊ณผ ๊ตฌ์ฒด์ ๋ฐ๊ฒฝ, ray์ ๊ธธ์ด, layerMask๊ฐ ์ฃผ๋ก ์ฐ์ธ๋ค.
๋๊ธ๋จ๊ธฐ๊ธฐ