
I am wondering if anyone out there is familiar with rudimentary programmatic movement, using radians and math. Even a few examples of equasions beyond vector = direction * speed would help. I know direction is based on _rotation, and an new _x/_y calculation on an object (game loop) is based _rotation, speed, and involves sine/cosine/tangent in some form, but this is about all I know. I checked out moock.org, but the info is not up to date (Flash 4 before built in math). Any help would be much appreciated. Thanks

try my site http://www.flashguru.co.uk for some examples of programmatic movement with flash 5.
Hope that helps!!
Regadrs FlashgUru

Well I'm not the greatest at this kind of stuff but I'll do my best to sum up everything I have learned in the past couple of days.
The first things that come to mind when I think of the new programmatic movement possibilities are sine/cosine waves (or just any trig curve for that matter). I'm sure there are many applications for it...having an object oscillate for some kind of game or who knows what else. If you want a little tutorial on how to "fine tune" a sine wave check out this.
Now if sine waves dont really interest you then maybe parametric curves will. The possibilities are virtually endless with parametric graphs. First you have three variables..."x", "y", and "t" (theta). The ordered pair is (t,x) and (t,y)..I hope I'm not confusing you because I am not all that good at explaining this stuff. You start with t=0 and increase to 2pi...in radians of course. But instead of just one equation like y=mx+b you have two: x=r*cos(t) and y=r*sin(t)...that right there graphs a circle with radius "r". I have two links for you having to do with parametric equations. The first is a link to a list of all different types of curves which are all now possible in Flash:
The Famous Curves Index
http://wwwgroups.dcs.stand.ac.uk/~...es/Curves.html
The next is a file using programmatic movement and parametric equations in a Flash file...check out this. It turns linear velocity into rotational velocity...the radius and speed of the rotation are all based on how close the mouse is the objects and how fast the mouse is moving.
And then to conclude the things I know about programmatic movement (which isnt very much...hopefully someone will come in and give you better stuff) lets talk about vectors. Now there are tons of different ways of doing notation for vectors and different forms of writing out vectors (things that are way beyond me) but my mediocre understanding tells me two basic things: a vector consists of a direction and a velocity... The direction is given as an angle (of course). Now personally, I think working with vectors is all cool and hip when working in the real world but when I do something in Flash I like xaxis and yaxis velocities...am I the only one?...I hope not. Well I'll tell you how to translate a vector into my so beloved x/y axis velocities. First of all if we thing of the x and y movements as legs of a right triangle we can think of the hypotenuse as the velocity right? Here's a picture:
Code:
\
 \
yvel  \ velocity
 \
 \
_______\
xvel
Well lets say we were given the direction of 20 degrees (I like degrees...not radians) and the velocity of 10 pixels/s (this has nothing to do with the picture I made) how would we change that to x/y vel.? Well we know that the sin(20) equals the opposite over the hypotenuse...or the y velocity over the regular velocity. Something like:
Code:
/
/ 
10 / 
/  yvel
/ 
/ 
/__20_____
xvel
sin(20)=y/10
cos(20)=x/10
Do you agree with that picture? I hope so because if you dont that means I either suck at teaching or I did something wrong. Well, in the case of the yvelocity, cant we just multiply both side by ten so that the right side will cancel out leaving you just "y" and the left side will be 10sin(20). So we have just proven something very relevant in programmatic movement (I think)...here are some equations you can use (its everything we just did except in one step):
Code:
Given "v" for velocity of a vector and "r" for direction of a velocity you can use this to solve for the x and y velocities:
xvel = v * cos(r)
yvel = v * sin(r)
Now I bet you want some applications dont you? Have you ever heard of a game called "Bang" (there were actually a bunch of names for it). Its where you have two characters standing on opposite sides of the screen with little obstacles like hills and buildings between them...then a user enters in an angle and velocity (sounds like a vector huh?) and the players shoot cannons at each other. Add in a little gravity and now you know how to make that game in Flash. I was actually planning on making it but I would love to see what you come up with as well.
Well thats about it from me...I really hope I didnt confuse you because it seems like my logic was skipping around throughout my post...well anyways...good luck.
< edit >
I just saw that Flashguru just replied...oh well...it took me way too long to type that so I dont want to delete it...
< /edit >

Ah man I cant believe I left out this link...here is a link, put together by Richard Wright (Dickee on the boards) with a bunch of other links to pretty much every math branch there is. I think in the "Physics" section there are some good websites discussing vectors.
http://www.werehere.com/forum/Artic...ks/index.shtml

nail has been struck by hammer!!
Ahab, I can't thank you enough. This is exactly what I needed to know...
Thankyou both.
[Edited by dullgrey on 09212000 at 01:21 AM]

Hey no problem...but it turns out I have one more chapter to include in this thread...Bezier Splines. You would definately want to look into Bezier splines if you are wanting very complex paths and better control of what your path looks like. Now although bezier curves may seem to be entirely great they get a little cpu demanding if over used. I just got through seeing a little example over at JZWAY where he had a bunch of bezier's define the path of some falling leaves and it got pretty slow sometimes. Well anyways although I am not smart enough to provide you with a good explanation I have come prepared with links:
The Dr.Math Forums: Bezier Splines:
http://mathforum.com/dr.math/problem...er12.3.96.html
Bezier Curves  this is where I learned all the math behind these curves:
http://moshplant.com/director/bezier/index.html
Flashkit Boards Thread  here is a discussion on bezier curves here at Flashkit:
http://www.flashkit.com/board/showth...threadid=12719
That should conclude my thoughts on the subject...great topic by the way. I am hoping others will see this and post their ideas/views/techniques.
Good luck.

hi,
hey that turbulent stuff looks familiar
I know this isn't the place to be using the 'd' word, but
if you want the basic theory behind it, check out the article I wrote for DirectorOnline last year:
Simulating turbulent particle behavior with Lingo
at...
http://www.directoronline.com/accessArticle.cfm?id=470
the syntax won't apply but the basic theory is the same
cheers,
glenn
http://redrival.com/gmitchell

Exactly man! That was a great article you wrote! That is where I got it from. Wow! Its cool to know that Director guys come to the Flash forums because I think that Director tutorials are written better than Flash ones...usually.

Hey ahab,
That a pretty neat little tute for sine curves u got there. I have been working on little sine curve of mine in the mean time. You could check it out im my experiments section Glenn I liked that turbulence stuff, just going thru it.

a piece of the puzzle
To move an object (movie clip) the key is definitely Ahab's trig above. But don't repeat my mistake of trying to shoehorn degrees into Actionscripts Math.sin Math.cos objects (a lesson learned the hard way: read the actionscript reference guide's element description sooner than later). To use sin/cos effectively in Actionscript degrees must be converted to radians. Conversion is simple:
There are 2PI radians in a circle, breaking down to about 57.296 dagree's p/radian. To be more acurate use:
x/(180/PI) where x is degrees....
i.e.
shipx = shipspeed * Math.sin (rotation/(180/Math.PI));
shipy = shipspeed * Math.cos (rotation/(180/Math.PI));
where shipx/y is loop generated coordinates and rotation is based on getproperty..._rotation
then execute..
if (shipthrust) {
// Executing Loop coordinates
_x += shipx;
_y = shipy;
}
_y is subtracted due to the coordinate layout of the screen where 0,0 is top left.
Hope this helps somebody.... Thanks to all who helped me.

Please stop it!
This thread has just ruined my weekend!
Seriously, excellent stuff  thanks Ahab et al!

The same goes for me! Thanks to all of you who were part of the solution to this query. I have just been asked to research this very subject so I appreciate being able to get such a good start from a site like this.
You guys rock!
siman

dullgrey,
Yep I made that mistake also beacuse I didn't know that most computer languages liked radians and I love degrees. Once you know that the trig math objects need a radian input it is easy to translate back and forth between the two measures...just like you said:
Degrees to radians: D = angle in degrees and R = angle in radians:
R = D * (pi/180)
and
Radians to degrees: D = angle in degrees and R = angle in radians:
D = R * (180/pi)
Nav,
Yeah I had seen your sine curve a few days ago and it was very cool. I once made a graphing calculator in Flash 4 and now that we have these new math objects you graph even more functions...just thought that may be something that would interest you...it would be a great addition to your experiments: A Flash 5 Graphing Calculator.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
