slingshot catapult and canon?

Subscribe to slingshot catapult and canon? 10 posts, 7 voices

Sign in to reply


 
avatar for DougWiiBoy DougWiiBoy 28 posts
Flag Post

does anyone know how to make or a tutorial to make a slingshot, canon and catapult in as2? They all need to be able to shoot a movieclip off or out of them and let it fly. It would be helpful if you could adjust the springiness of the slingshot and power of the canon.

thanks!

 
avatar for Bray21 Bray21 379 posts
Flag Post

Oh yeah ill get right to it!

 
avatar for DougWiiBoy DougWiiBoy 28 posts
Flag Post
Originally posted by Bray21:

Oh yeah ill get right to it!

Thanks!

 
avatar for DougWiiBoy DougWiiBoy 28 posts
Flag Post

it can be in as3 if you can find tutorials for that.

 
avatar for skyboy skyboy 1230 posts
Flag Post

Click Here

 
avatar for DougWiiBoy DougWiiBoy 28 posts
Flag Post
Originally posted by skyboy:

Click Here

I already tried google and nothing for slingshot or catapult. didnt look for canon though.

 
avatar for Blank_64 Blank_64 504 posts
Flag Post

figure out the formula for a parabola… then how to fire an object towards the mouse… (both on google)
then combine them. poof, a cannon with a shot that arks

 
avatar for nrfpt nrfpt 1 post
Flag Post

Maybe you can find it here:
http://pelfusion.com/tutorials/35-flash-game-development-tutorials-fla-files/

 
avatar for GhostIV GhostIV 15 posts
Flag Post

Cannon is easy
You just have to define the initial speed of the bullet and then change it over time with predefined values.

Something like this:


var spdX,spdY,gravityMod;

Define the gravityMod with some value.
Then when the cannonball is shot you define the starting speed. I recomend looking up the move based on rotation method.
Then you just change the coordinates by the speed value and then change speed on predefined values. like this:


this.x+=spdX;
this.y+=spdY;
spdY-=gravityMod;

This way your ball will start falling down over time.
You could also add air friction and wind as an additional parameters and modify speed some more.

CATapult and slingshot are harder, because you have to calculate how the ball moves before it leaves the … ummm… however the thing that holds the ball is called… sling? I cant say anything on this part.
But after that in a free flight its pretty much the same.

I hope i helped at least a little. Godspeed.

 
avatar for the8bitYoda the8bitYoda 58 posts
Flag Post

A sling can be viewed as a spring, so figure out the force exerted on the object you’re firing by the displacement from the starting point of the sling using Hooke’s law. (Force=-spring constant*displacement). The spring constant is just some number; the higher it is, the harder the spring is to pull back. So code for it would look something like


//The rubber band is pulled back from the starting point of sling, so find
//the displacement in both the x and y directions
//The rubber band’s x and y coordinates should refer to the center of the //rubber band.
displacementX=rubberBand.x-sling.x;

//This is switched around because of Flash’s coordinate system
displacementY=sling.y-rubberBand.y;

//The force exerted on the object using Hooke’s law.
slingForceX=-(springConstant)displacementX;
slingForceY=-(springConstant)
displacementY;

//Now that you have the forces exerted on the object, change it’s //velocity, spdX and spdY. Before you release the sling, the objects
//spdX and spdY will be 0 (it’s not moving).
spdX+=slingForceX;
spdY+=slingForceY;

//Account for gravity (GhostIV’s post)
spdY-=gravityMod;

//Move the object (and the sling rubberband)
this.x+=spdX;
this.y+=spdY;
rubberband.x=this.x;
rubberband.y=this.y;


So that’s about it, you’ll need to stop the sling rubber band when it reaches the sling base (it’s displacement will then be 0 and the slingForceX and slingForceY will be 0).

EDIT: Should be
displacementY=rubberBand.y-sling.y;

http://en.wikipedia.org/wiki/Spring_%28device%29#Physics

Sign in to reply


Click Here