c# - Detecting possible projectile vs shield collision -


i'm trying detect, whether projectile going hit shield - , collision happen.

enter image description here

on image, can see situation. though a , b projectiles in approximately same distance shield centre s, 1 of them collide shield , other 1 not.

enter image description here

solution mathematically straightforward use mathematical equation of circle , equation of line of projectile path.

with pen , paper, can calculate that. however, have bad experience implementing analytic geometry directly.

also, return positives projectiles leaving shield. how filter them?

enter image description here

second approach, friends idea, measuring minimal distance between projectile path , shield centre - if l smaller r, collision happens.

it seems easier implement, doesn't let me know collision happen.

i work in 2 dimensions. i'm using c# , unity engine, universal solutions welcome.

the projectile is, of course, considered point 0 size.

use parametric equation of trajectory: x= x0 + t.p + x0, y = t.q + y0 (starting (x0, y0) in direction (p, q)).

plug circle equation (x - xc)^2 + (y - yc)^2 = r^2, , get:

(t.p + dx)^2 + (t.q + dy)^2 = (p^2+q^2).t^2 + 2.(p.dx+q.dy).t + dx^2+dy^2 = r^2. 

this quadratic equation in t. shield hit whenever there positive root.

if projectile has nonzero radius r, imagine deflate projectile 0 , inflate target r + r.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -