ย  ย  //์ด์ฐจ๋ฐฉ์ •์‹์˜ ๊ทผ์„ ๊ตฌํ•˜๋Š” ์ฝ”๋“œ

ย  ย  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์ธ ๊ฒฝ์šฐ์—๋Š” ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค

๋‚˜์ค‘์— ๋‹ค์‹œ ์“ธ๋ ค๊ณ  ์˜ฌ๋ ค๋ด…๋‹ˆ๋‹ค

์˜ค๋ฅ˜๊ฐ€ ์žˆ๋‹ค๋ฉด ์•Œ๋ ค์ฃผ์„ธ์š”