Cannon Fire

Get help using Construct 2

Post » Wed Mar 28, 2012 5:17 am

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):

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 that I found here.
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Wed Mar 28, 2012 6:00 am

It doesn't rotate even when the "manual_fire" key exists ?
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Wed Mar 28, 2012 6:41 am

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?
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Thu Mar 29, 2012 4:49 am

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.

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?
B
25
S
8
G
8
Posts: 71
Reputation: 5,307


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 24 guests