Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / shooting a cannon ball

Author
Message
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 4th Feb 2013 11:38
can someone give me a simple example of shooting a cannon ball out of a cannon at the given cannon angle (that is adjustable by buttons) using physics for the ball of course! been trying all weekend but cannot work it out myself... Thanks!

Hail to the king, baby!
ProfVersaggi
12
Years of Service
User Offline
Joined: 6th Apr 2012
Location: Maastricht Netherlands / Chicago, USA
Posted: 4th Feb 2013 12:55
I can give you an example of that but it'll be a battleship turret and projectiles if that's acceptable ... I've worked on that thorny problem for a while and have some experience solving it ...

----
From the Desk of Prof Versaggi ...
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Feb 2013 13:04
i am not at home but its easy.
the angle give you the speed with sin/cos in x and y direction.
the weight and gravity pull your ball down over time.

angle#=45 //degree
speed#=???

vx#=cos(angle#)*speed#
vy#=sin(angle#)*speed#

SetSpritePhysicsImpulse()

http://www.appgamekit.com/documentation/Reference/Sprite.htm
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 4th Feb 2013 13:47 Edited at: 4th Feb 2013 13:57
thank you marcus, this explains fully where I was going wrong! I see how it works now. The only thing is though that on different angles it does not travel as far with the same speed, so if I set the angle at 90 for instance, it would reach the top of the screen with a speed of say 4, but change the angle and of course it doesnt travel as far, if I want the user to simply be able to adjust the power of the shot, which I guess is just the speed? then how do I overcome this ?!

Hail to the king, baby!
ProfVersaggi
12
Years of Service
User Offline
Joined: 6th Apr 2012
Location: Maastricht Netherlands / Chicago, USA
Posted: 4th Feb 2013 14:18
Be sure to set your gravity to Zero ...

----
From the Desk of Prof Versaggi ...
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Feb 2013 12:32 Edited at: 5th Feb 2013 12:38
if you shoot up it can't goto the right without wind.
but you can limit the angle that it must move a little bit to the left or right.
also importent is the physic scale because the default
was set up for 100% width = 100 meters.
you can simulate wind by add acceleration at x.

alternative without physics you can use start/end coordinates
and the angle/flight path is the result of a formula.

Login to post a reply

Server time is: 2024-05-07 22:58:18
Your offset time is: 2024-05-07 22:58:18