[FMX] Canon force and trajectory

ok I have a canon, the user can se the force and trajectory and i want it to shoot and have the cannon ball thing go the height and distance it would in real life.

I attached what I have so far, its just the canon and it lets you set the angle and force. It should give you an idea of what I mean if you dont know.

Ugh… I hate the interfacing of Flash between 5 and MX… lol

That’s the only beef I have with Macromedia… Make the two version convert to eahc other if need be… :-p… But anyways… Enough complaining and on to the problem at hand…

Well I couldn’t tell what you had set up because I can’t open it… How dumb huh? I might just get Flash MX and have both versions on here… lol

:cyclops: I did get to see the game and how it works though… And I made a game like this in C++ about 2 years ago…

You will have to come up with a formula to judge the amount of force and what angle you have it set on and convert these into a proper x and y distances… Okay… say… 85 force and angle 45 degrees would give you an x of 4 and a y of -4… Basically this is stating each time it comes on this frame it goes…

[COLOR=green]
the x of the movie moves over x amount… thus it moves 4…
the y of the movie moves over y amount… thus it moves -4…
[/COLOR]
[COLOR=sandy brown]
Btw… If you need help trying to grab on to those forumals I was tlaking about… Give me a msg saying so or contact me at mentalconcepts@hotmail.com
[/COLOR]

But… Like you said… That would just make the ball go up at 45 degrees forever and ever and ever… So… WHat do we have in real life? Gravity… Alls you have to do… before moving the bullet or cannon ball in the y direction put this in…

[COLOR=green]
y += .1;
[/COLOR]

So each frame will go down by .05… Toy around with this number… Not sure what works good or not anymore… lol

Basically saying…

[COLOR=green]
Loop 1 y = -4
Loop 2 y = -3.9
Loop 3 y = -3.8
Loop 4 y = -3.7
Loop 5 y = -3.6
and so on and etcetera
[/COLOR]

This should make it look like a nice and even arc :slight_smile:

Hope this helps… Don’t know if it did or not… Might seem confusing. I have a lot of notes on this stuff though… Diagrams and stuff… :slight_smile:

Good Luck
<:} Marz <:}

Yeah, well the first step would be to launch the ball at the right angle. Straight line. Then you can add gravity (tute somewhere).

pom :slight_smile:

Yea, I figured that out about doing the degree thing frist then adding in the gravety. Now to figure out that formula. Any more help would be nice. :wink:

What’s your problem? :eye:

*Originally posted by ilyaslamasse *
**What’s your problem? :eye: **

Well basicaly I wanna know how to figure out the distance and arc height and stuff like that when given the force and angle. Theres just some formula that I dont know. Know wut I mean?

Well, the real formula won’t be helpful because you won’t be able to use it in flash. What playamarz and I said: get the angle, send the bullet straight, and then add gravity.

I dunno if the formula would work or not but i think it would help me figure it out. anyway, how would you solve the problem?

like look at what playamarz said

*Originally posted by playamarz *
You will have to come up with a formula to judge the amount of force and what angle you have it set on and convert these into a proper x and y distances… Okay… say… 85 force and angle 45 degrees would give you an x of 4 and a y of -4… Basically this is stating each time it comes on this frame it goes…

he said:
85 force and angle 45 degrees would give you an x of 4 and a y of -4

but how do you get those numbers, what if the angle was like 37.5?

Ever heard of cos and sin? That’s the ticket. You’ll have to project the force on both axis.[SIZE=1]I’m trying to write a tutorial about all this but it’s a long process[/SIZE] :frowning:

*Originally posted by ilyaslamasse *
**Ever heard of cos and sin? **

Heard of it…

I’m trying to write a tutorial about all this but it’s a long process

So I guess this isnt genna be easy… oh well, back to work.

Yeah… it can be a long and sought out process to do it… Basically it’s like this…

Lemme show you a life example…

Angle = 25 degrees
Force = 80 power

Allright now… In calculus I learned about a unit circle… Pretty much this states that a circle is 1 unit round all around it… Which means it has a radius of 1 unit. On this method… Such angles like 90 degrees were easy to figure out… Likewise with this situation…

Lemme show you an image of the line at 25 degrees (close at least… hehe)

This here shows you the basic of it… Sorry didn’t feel like being artsy… As you can see… We have ourselves a line… Woop-di-do… Right? wrong… You can figure out how much you need to do everything into by this next image…

See the orange and teal lines? Those are the two lines that will help us figure out how much of an x and y we need to put… We will just multiply those numbers by a certain number we get from the force then to figure out our final two ending x and y numbers.

So we know the following… The angle is 25 degrees and because we are doing this on a unit circle the length of the longest line… The blakc line… Is 1 unit… Now alls we need is to find the other two sides… Take a look at this equation.

[COLOR=red]
sin 25 degrees = opposite side from angle / 1 unit;
[/COLOR]

Thus you can say that…

[COLOR=red]
sin 25 degrees = opposite side from angle
[/COLOR]

If you figure this out you get that the opposite side of the angle will be : [COLOR=red] .4226… [/COLOR]

Now that you have the opposing side’s length… Now alls you have to look foris the adjacent side’s length… Well Use this this equation…

[COLOR=red]
cos 25 degrees = adjacent side from angle / 1 unit;
[/COLOR]

Thuis you can say that…

[COLOR=red]
cos 25 degrees = adjacent side from angle
[/COLOR]

If you figure this little bit of code out you find out the the length of the adjacent side will be: [COLOR=red] .9063… [/COLOR]

Now… You may ask… What can you get out of those two numbers… Well it is simple… Just make unit = pixel and you to go to that point you need to go right .9063 of a pixel and up -.4226 of a pixel… Unfortunately… You gotta remember the axis on flash is backwords for the y… Blah. That can be a pain can’t it? lol

Now… We have equations to find the starting x and y directions… BUT WAIT… There is more… Cause that would be the same distance over and over and would make a for a dull game to have weak power like that all aorund… So… How to implement a force into your game…

So… After you figure out which decimals you have for your x and y’s… Let’s add something to this…

We chose a force of 80 power… Now if you think about this… That’s alot of power to put as 80 pixels so… let’s chop it down by 10…
80 / 10 = 8. 8 pixels seems alot. And I mean alot mroe manageable… Now… Let’s multiply this new number by the decimal numbers we had earlier to get the final number amounts…

x = x * 8;
y = y * -8; (Notwe… Since it won’t automatically make your y a negative… We want to multiply it by a negative amount of force…)

newx = .9063 * 8;
[COLOR=red] newx = 7.2504 [/COLOR]
newy = .4226 * -8;
[COLOR=red] newy = -3.3808 [/COLOR]

Therefore… You’re new bullet will travel each frame at a rate of 7.2504 in the x direction and -3.3808 in the y direction…

I’m pretty sure you can apply a couple of variables to what I just said and work it out with your game…

Good Luck And I hope this Helped
<:} <:} Marz <:} <:}

w00t, thanks alot man, I get it know.

thankies :wink: