Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Updated this post and the one at Math SE (, hope this makes more sense.

I previously posted a question (about half an hour ago) involving computations along line segments, but the question and discussion were really off track and not what I was trying to get at. I am trying to work with an FPS engine I am attempting to build in Java.

The problem I am encountering is with hitboxing. I am trying to calculate whether or not a "shot" is valid.

I am working with several approaches and any insight would be helpful. I am not a native speaker of English nor skilled in Math so please bear with me.

Player position is at P0 = (x0,y0,z0), Enemy is at P1 = (x1,y1,z1). I can of course compute the distance between them easily. The target needs a "hitbox" object, which is basically a square/rectangle/mesh either in front of, in, or behind them.

Here are the solutions I am considering:

  1. I have ruled this out...doesn't seem practical. [Place a "hitbox" a small distance in front of the target. Then I would be able to find the distance between the player and the hitbox, and the hitbox and the target. It is my understanding that you can compute a circle with this information, and I could simply consider any shot within that circle a "hit". However this seems not to be an optimal solution, because it requires you to perform a lot of calculations and is not fully accurate.]

  2. Input, please! Place the hitbox "in" the player. This seems like the better solution. In this case what I need is a way to calculate a circle along the vector, at whatever position I wish (in this case, the distance between the two objects). Then I can pick some radius that encompasses the whole player, and count anything within this area a "hit".

  3. I am open to your suggestions. I'm trying to do this on paper and have no familiarity with game engines. If any software folk out there think I'm doing this the hard way, I'm open to help!

Also - Anyone with JOGL/LWJGL experience, please chime in.

Is this making sense?

share|improve this question
Delete it then? – XiaoChuan Yu Apr 4 '12 at 4:18
I've rolled it back until it gets deleted. As maybe someone will find an answer or find it of use. – Byte56 Apr 4 '12 at 5:08
It's really hard to understand what exactly you're wanting to find. It sounds to me like you should think of this problem more in terms of circles and radii than in points and line segments. – stephelton Apr 4 '12 at 5:11
Stephelton, I think that is the case. I have updated the question. Maybe someone can point me in the direction of appropriate math or API calls. – Matt Szaro Apr 4 '12 at 5:20
up vote 2 down vote accepted

Player position is at P0 = (x0,y0,z0), Enemy is at P1 = (x1,y1,z1). I can of course compute the distance between them easily. The target needs a "hitbox" object, which is basically a square/rectangle/mesh either in front of, in, or behind them.

The hitbox should always be 'inside' the target and depending on how hard you want it to be the hit something it should totally encompass the target or be slightly smaller than the target.

Now you have a hitbox and a bullets firing in the direction of the hitbox. What you need to do is calculate if a ray, following the path of the bullets, will intersect with the hitbox. This is a very well documented problem.

You can find all sorts of math and source code here for X->Y intersection:

See that you can also use sphere's (very easy) cylinders and other primitives to test if a bullet hit the target.

Finally I would like to point out that you don't need to limit your self to one bounding primitive per object. Often it's a better fit to use multiple and check against each one of them:

Bounding sphere's

You should also look at this question: Best/Efficient way to implement a 3d Collision

After you have the basic collision detection algorithms implemented and things seem to get slow when there are many collidable objects in the scene you should look up spatial partitioning and octrees.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.