Bow Arrow shooting 2d game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By aadyainfotainment

I have been struggling a lot for tutorials about shooting arrows from a bow.

I do not know how to write code for:

  • stretching the string of the bow by clamping to an extent
  • release the arrow in a parabola
  • show the path where the arrow will hit.

Can anyone please help me to create this game?

:bust_in_silhouette: Reply From: Wasiim

For the stretching of the arrow you can use a basic quadratic Bezier Curve, where you simply extend the X position of the middle point back and you can have some max value for how far they can pull it back, if that middle point is collinear with the other two, then you get a line.

Check out the tutorial on the Godot docs

The Curve2D class will do these bezier curve calculations for you and draw the curve

If you want the bow to have realistic projectile motion without air resistance, you can use the following equations.

where the path is computed based on some maximum speed m_speed and the mouseDir which is probably better to rename to arrowDir, and we assume here it’s a unit vector, and you probably want to clamp it based on some min and max angle. m_speed is dependent on how far back the arrow string is pulled, which we figured out in the example above.

I’m not sure if Curve2D can be used to compute points for anything other than a bezier curve. But if it can, you can use that to generate the path curve also. And then use PathFollow2D to make the arrow follow that path.

If that’s not an option you can computer the curve yourself using small increments of t, maybe like 0.04