ย ย //์ด์ฐจ๋ฐฉ์ ์์ ๊ทผ์ ๊ตฌํ๋ ์ฝ๋
ย ย public static float calc2D(float a,float b,float c)
ย ย {
ย ย ย ย return ((-b - Mathf.Sqrt(Mathf.Pow(b, 2) - 4 * a * c)) / (2 * a));
ย ย }ย
ย ย //๋ฐฉํฅ์ ๊ตฌํ๋ ์ฝ๋
ย ย public static float dir(Vector2 Bloc, Vector2 Ploc,Vector2 Pvelo,float Bspeed)
ย ย {
ย ย ย ย Vector2 dis = Ploc - Bloc;
ย ย ย ย float a = -Mathf.Pow(Bspeed,2)+ Mathf.Pow(Pvelo.x, 2) + Mathf.Pow(Pvelo.y, 2);
ย ย ย ย float b = 2*(dis.x*Pvelo.x+dis.y*Pvelo.y);
ย ย ย ย float c = Mathf.Pow(dis.x,2)+ Mathf.Pow(dis.y,2);
ย ย ย ย float time = calc2D(a,b,c);
ย ย ย ย Vector2 returningData = Bloc - (Ploc+time*Pvelo);
ย ย ย ย float angle = Mathf.Atan2(returningData.y, returningData.x) * Mathf.Rad2Deg;
ย ย ย ย return (angle)+90;
ย ย }
Bloc = ์ด์์ ์ฒ์ ์์น
Ploc = ๋์์ ์ฒ์ ์์น
Pvelo = ๋์์ด 1์ด๋์ ์์ง์ด๋ ๋ฐฑํฐ
Bspeed = ์ด์์ ์๋
์ฌ์ฉ๋ฒ
Quaternion.Eular(0,0,dir(/*data*/))ย ย //์ด ๊ฐ๋๋ก ์ด๋น Bspeed๋งํผ ๊ฐ๋ฉด ๋์์ด Pvelo๋งํผ ์ด๋น ์์ง์ธ๋ค๊ณ ๊ฐ์ ํ ์ ๋ช ์คํ๊ฒ ๋จ
์ค๋ ฅ์ด ์๊ฑฐ๋ 3d์ธ ๊ฒฝ์ฐ์๋ ์ฌ์ฉํ์ง ๋ชปํฉ๋๋ค
๋์ค์ ๋ค์ ์ธ๋ ค๊ณ ์ฌ๋ ค๋ด ๋๋ค
์ค๋ฅ๊ฐ ์๋ค๋ฉด ์๋ ค์ฃผ์ธ์
๋๊ธ 0