- Home /
Hit box based off of a parabola
Say i've calculated a parabola based off of, y = x^2 + x, how would i apply this parabola onto a hitbox so that only things touching the line of the parabola will be detected?
Answer by Fattie · Dec 27, 2012 at 11:30 AM
Dude - could you simply throw something - using the amazing physics engine entirely built in to Unity, the whole reason for using Unity! - and just see if it bounces in to the box in question?
A parabola/box intersection test, man that is tricky to do properly!
The very simple solution: Get the x value of the middle of your box. Find the Y value where that would be on the parabola. WIthin a reasonable allowance, see if in fact that's where the box is. That's it!
More fancy .. do the same thing for all four points of the box, and proceed in the obvious way from there, testing for each "edge" of the parabola cuts that edge.
@Fattie ~ I understand that i could "throw" something as you put it. But i'm not wanting to instantiate a (bullet in this case) every time a gun is shot, this is extremely CPU intensive and i prefer it to do quick like Source Engine's HitScan hit detection, except its affected by some properties such as wind. Perhaps ill do the parabola x/y method you suggest. If it works I'll accept your answer as the final answer.
Hi Phx
in video games, you do not Instantiate bullets. You use a pool
Here is a long answer about it ...
http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html
Every vid game you've ever played works like that.
Can you tell us how many of these partabola-following cannonballs, you play to have on screen at the one time? five, 10, 100, what's it like ?
Pleased to be able to help!
Your answer
Follow this Question
Related Questions
Angle calculation not working?? 2 Answers
Calculate a new position instead of using Vector3.back 1 Answer
Problem with calculating damage, value returning 0 1 Answer
Calculations Wrong? 1 Answer
Mathf.Lerp like User Define Function 2 Answers