Cannon Fire

0 favourites
  • 4 posts
From the Asset Store
Top down zombie survival mechanics pack in the style of Cannon Fodder.
  • How can I have a cannon shoot a ball (with physics behavior) so that the ball's trajectory goes through the point where the user clicks?

    This is what I tried to do to get the cannon at the right angle, but the cannon doesn't rotate at all (0 degrees):

    <img src="http://dl.dropbox.com/u/52788071/cannon_angle.png" border="0">

    I got the formula from Wikipedia.

    The ball gets shot with an impulse of 0.6 at Cannon.Angle. I convert this to velocity using the formula <img src="http://easycalculation.com/physics/classical-physics/images/impulse-velocity.gif" border="0"> that I found here.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It doesn't rotate even when the "manual_fire" key exists ?

  • http://dl.dropbox.com/u/52788071/cannon_fire2.jpg

    The "manual_fire" key is just a way to access a backup option in case the "automatic" one doesn't work. (Which it's not right now.)

    I'm not very good at physics calculations; what did I do wrong in the formula? Or do I have the wrong formula?

  • I calculated the velocity that the ball starts moving at and realised that the formula assumes that the cannon is at (0, 0). So I subtracted the cannon's coordinates from the mouse's coordinates.

    <img src="http://dl.dropbox.com/u/52788071/cannon_angle2.png" border="0" />

    Note: I blurred out parts that are unrelated to the problem.

    Now, when the mouse is anywhere to the left of the cannon, it points almost straight up (270.00009316509215 degrees). When the mouse is anywhere to the right of the cannon, it points almost straight down (89.99999794984215 degrees).

    Also, the formula assumes that (0, 0) is in the bottom-left corner instead of the top-left. I'm not sure how to correct this.

    Can anyone please help?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)