

Projectile intersection vector 2d code#
Here are some select snippets of code to illustrate how I represent physical objects: public abstract class Physical : GenericGameObject, IRenderable Acceleration is just a change in velocity over time. Let's also remember from our calculus that velocity is just a change in position over time (note: velocity is a speed and direction). So, let's represent our projectile with a 3D coordinate which indicates its position in coordinate space by using a Vector3. If we left everything alone, our projectile would follow the same path, regardless of where we want it to go. However, since our angle and projectile speed are already constant, we're going to have to change gravity in order to actually hit our target. Now, gravity is typically a constant for projectile motion equations. The only force which will act on our projectile in flight is going to be gravity. I am going to ignore the effects of air resistance, wind direction, air density, temperature, etc. I am going with basic, newtonian projectile motion in euclidean space. Somehow, we will need to detect this situation.īonus points: We want to minimize the time of flight for our projectile by choosing the firing angle which has the shortest flight time (ie, a direct shot vs. If this is the case, (to borrow an artillery term) we need to perform a high angle fire mission to hit the target in defilade. If I wish, I should be able to increase or decrease the speed of my fireball and still get a perfect firing solution.Įxtra problems: The target may be hiding behind a hill. I also want to launch my fireball at an arbitrary angle, but for now I am using 45 degrees (pi/4).

Fireballs are a bit magical as well, so when I launch the fireball, it should always have the same speed for every fireball. My fireball *must* pass through this point.

I am launching a fireball projectile at another position in 3D space. This position is given by the coordinates X, Y, Z. Problem description: I am a wizard standing at any given position in 3D space. YEAH!!! I got it! I got my math down for projectile motion in 3D space and it works!Īlright, so, let me explain what I was trying to do and how I figured it out.
