Forum Topic: Trigonometric movement?

(151 views • 8 replies)

This topic is 1 page long.

<< < > >>
None

zuperxtreme

Reply To Post Reply & Quote

Posted at: 11/8/09 04:54 PM

zuperxtreme NEUTRAL LEVEL 08

Sign-Up: 01/02/05

Posts: 1,629

:/

Not really sure how to apply the math to get my desired effect.

There are 3:

Sinusoidal wave to a target and invert when it reaches it's destination.

Sinusoidal wave towards a target.

Parabola? Line, half a circle turn, line.

Anywho, I don't want to draw the lines, I want an object to move in those paths. Ideas?

For visual aid:

Trigonometric movement?


Sad

Archon68

Reply To Post Reply & Quote

Posted at: 11/8/09 05:53 PM

Archon68 LIGHT LEVEL 22

Sign-Up: 09/09/07

Posts: 3,482

You can use the Math class to take advantage of basic trig functions.

AS3: http://livedocs.adobe.com/flash/9.0/Acti onScriptLangRefV3/Math.html
AS2: http://livedocs.adobe.com/flash/9.0/main /wwhelp/wwhimpl/common/html/wwhelp.htm?c ontext=LiveDocs_Parts&file=00001842.html

I code in AS2, in case I forgot to mention it.

BBS Signature

None

polym

Reply To Post Reply & Quote

Posted at: 11/8/09 08:29 PM

polym LIGHT LEVEL 10

Sign-Up: 10/02/07

Posts: 804

At 11/8/09 05:53 PM, Archon68 wrote:

Hate to emphasize your stupidity once again but he's asking how to apply the math.


None

Montycarlo

Reply To Post Reply & Quote

Posted at: 11/8/09 08:48 PM

Montycarlo LIGHT LEVEL 19

Sign-Up: 03/14/05

Posts: 742

Didn't you ever do functions in Maths class?

f(x) = cos(2x)/sin(x)
Create a rule like that and substitute the time elapsed into x (Or whatever variable you wish to use)

Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.


None

henke37

Reply To Post Reply & Quote

Posted at: 11/9/09 01:17 AM

henke37 NEUTRAL LEVEL 23

Sign-Up: 09/10/04

Posts: 3,665

That doesn't turn at a specific point.

Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.


None

zeefoes

Reply To Post Reply & Quote

Posted at: 11/9/09 03:03 AM

zeefoes NEUTRAL LEVEL 02

Sign-Up: 07/31/09

Posts: 6

The two lines below will get your object to move in the direction it's facing.
bullet.x += Math.sin(bulletAngle*Math.PI/180) * bulletSpeed;
bullet.y += Math.cos(bulletAngle*Math.PI/180) * -bulletSpeed;

Now you have to either make checkpoints, or tween a single checkpoint along the path. After you do that you need to make your moving object face the checkpoint. To do this you calculate the angle of a vector between your two objects and plug it into the following formula.

angle = tan inverse ( X / Y)
X is (bullet.x - checkpoint.x);
Y is (bullet.y - checkpoint.y);

if(bullet.rotation <= -5) bullet.rotation++;
if(bullet.rotation >= 5) bullet.rotation--;
These two if statements should keep your object facing the checkpoint by comparing your objects rotation to the angle of the vector, and if it's facing the checkpoint it will go towards it.

You may have to convert to or from radians... or maybe change the angles in the if statements for this to work, the concept works but the code is untested. Hope this helps.


None

zeefoes

Reply To Post Reply & Quote

Posted at: 11/9/09 03:07 AM

zeefoes NEUTRAL LEVEL 02

Sign-Up: 07/31/09

Posts: 6

Or you could always use tweenmax, it's probably easier than what I posted above.
www.tweenmax.com/


None

henke37

Reply To Post Reply & Quote

Posted at: 11/9/09 04:33 AM

henke37 NEUTRAL LEVEL 23

Sign-Up: 09/10/04

Posts: 3,665

y=baseline+sin(phase+=phasespeed)*amplit ude for basic waving. Then just add a normal reversal on the x axis.
For the path with a halfcircle turn, you need different movement modes so that you can know what you should be doing right now.

Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.


Happy

zuperxtreme

Reply To Post Reply & Quote

Posted at: 11/9/09 03:58 PM

zuperxtreme NEUTRAL LEVEL 08

Sign-Up: 01/02/05

Posts: 1,629

Thanks everyone! I'll check over this carefully when I'm at home with Flash.


All times are Eastern Standard Time (GMT -5) | Current Time: 05:48 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!