I'm fairly new to game logics, C#/XNA (The language/library of choice) and bezier curves in general, and is stuck in my current project. I'm going to try to explain as thoroughly as I can what the issue at hand is.

Illustration of the issue
The illustration above shows a line (P/Player) and three cubic bezier curves (A/B/C = "Enemies") between the time interval 0 ≤ t ≤ 1.

When the player holds down the right arrowkey, the player will move in a linear path to the right accordingly to a time variable (t). If the player also holds down the "fire button", the player character will shoot out bullets with a width of about 5 px from the top of it.

If the engine I have in mind is going to work, I will have to know precisely for how long period of time the enemies moving in their cubic bezier curves are being exposed to these bullets being shot out of the player. E.g. during the timespan of 0 ≤ t ≤ 1, enemy A will be exposed to bullets for a total of 0.43 units, B = 0.27 and C = 0 (these are made up results)

Which would be the most efficient and best way to take on this issue? So far I'm thinking of solving it by finding out the roots of the intersection of the line and the curve on the X-Axis to know if the players bullets will make contact during the timespan. But even if they do make contact, how can I make sure which enemy the player hits if the enemies paths kind of "overlap" eachother (like A and B in the picture)?

Some facts about the bullets that could clarify the behavior of the bullets I have in mind:

  • Bullets can't penetrate enemies. When it hits it's first target, it does not affect the one's behind it
  • For now, I'm satisfied if someone could come up with a solution without "bullet travel time" in mind. That the bullets hits instantly doesn't bother me too much. Bonus points if "travel time" is added in the solution of course.
  • In the picture, I show two lines. I would like to be able to multiple bullets being able to fire from different starting points on the player (like a dual-shot, quad-shot ect).

To sum my question up: (Quick reference guide)
When player goes to the right within 0 ≤ t ≤ 1, for how long does the player's bullets collide with the enemies?

  • 1
    \$\begingroup\$ I don't understand. Why are you doing this instead of just plain AABB collision detection? Are you just asking how to find the intersection between a ray and a bezier curve? \$\endgroup\$ – Anko Mar 12 '14 at 13:12
  • \$\begingroup\$ +1 for Anko. This seems like a sledgehammer to crack a nut. If the only goal is to find collisions between the bullets and the enemies, then there are much more simple ways to do it. \$\endgroup\$ – Laurent Couvidou Mar 12 '14 at 20:34
  • \$\begingroup\$ Okay, I think you're right. It is a bit too ambitious for what I'm trying to do, and I came up with a much easier solution using the plain AABB collision method. I'm sorry, but I'm very new to this \$\endgroup\$ – user1974555 Mar 13 '14 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.