Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKhatharr

Posted 20 May 2012 - 05:54 PM

I'm not a C# user, but looking at your bullet.cs I see what looks like some problems.

Firstly, you have a member function named "draw" which is doing work that is not related to drawing: namely it's updating the bullet logic and then performing the draw.

Updating the logic for the object should belong to its own function.

Examining the logic in question, you adjust the position of the bullet according to the velocity factors which the object was created with and then do some bounds testing. While this could work theoretically I think you'd have better luck using point-to-point interpolation:

*When you create the object give it a starting position, an ending position and a velocity..
*Use Pythagorean Theorem to calculate the distance between the two points. (dest_x - start_x is your triangle's base, dest_y - start_y is your triangle's height. The hypotenuse is the distance you need to travel.)
*Determine how many frames/steps are required to travel this distance at the desired velocity.

*Then during the bullet's update set its X to ((dest_x - start_x) * cur_step) / total_steps
*And it's Y to ((dest_y - start_y) * cur_step) / total_steps
*Increment cur_step
*When cur_step == total_steps then explode the bullet

As a side note, this isn't really a DirectX or XNA related question, and your topic title isn't really helpful for grabbing the attention of people that may know answers to your specific question.

Hope that helps. Posted Image Good luck with the project!

P.S. - Depending on your coordinate orientation you may need to reverse (dest_y - start_y) to (start_y - dest_y) and possibly also with the x dimension. If the bullet goes the wrong direction, that's your sign. ;)

#1Khatharr

Posted 20 May 2012 - 05:51 PM

I'm not a C# user, but looking at your bullet.cs I see what looks like some problems.

Firstly, you have a member function named "draw" which is doing work that is not related to drawing: namely it's updating the bullet logic and then performing the draw.

Updating the logic for the object should belong to its own function.

Examining the logic in question, you adjust the position of the bullet according to the velocity factors which the object was created with and then do some bounds testing. While this could work theoretically I think you'd have better luck using point-to-point interpolation:

*When you create the object give it a starting position, an ending position and a velocity..
*Use Pythagorean Theorem to calculate the distance between the two points. (dest_x - start_x is your triangle's base, dest_y - start_y is your triangle's height. The hypotenuse is the distance you need to travel.)
*Determine how many frames/steps are required to travel this distance at the desired velocity.

*Then during the bullet's update set its X to ((dest_x - start_x) * cur_step) / total_steps
*And it's Y to ((dest_y - start_y) * cur_step) / total_steps
*Increment cur_step
*When cur_step == total_steps then explode the bullet

As a side note, this isn't really a DirectX or XNA related question, and your topic title isn't really helpful for grabbing the attention of people that may know answers to your specific question.

Hope that helps. :) Good luck with the project!

PARTNERS