Hi Kevin,

It's quite simple actually. If you know the angle (it need to be in radians)
all you need after that is the speed of motion. To know the movement in the
x axis it's the cosine of the angle, for the y axis, it's the sine of the
angle so you will have the following :

mc._x = Math.cos(angle)*speed;
mc._y = Math.sin(angle)*speed;


And here is a quick example for that :

import mx.utils.Delegate;

var object:MovieClip = this.object;
var angle:Number = 45;
var DEGtoRAD:Number = Math.PI/180;
angle *= DEGtoRAD;
var speed:Number = 5;
object.onEnterFrame = Delegate.create(this, moveObject);

function moveObject():Void {
        object._x += speed*Math.cos(angle);
        object._y += speed*Math.sin(angle);
        var leftBorder:Number = object._x-object._width;
        var rightBorder:Number = object._x+object._width;
        
        var topBorder:Number = object._y-object._height;
        var bottomBorder:Number = object._y+object._height;
        
        var initY:Number = -object._height;
        var initX:Number = -object._width;
        if (leftBorder >= Stage.width) {
                object._x = initX ;
        } else if (rightBorder <= initX) {
                object._x = Stage.width + object._width;
        } else if (bottomBorder <= initY ){
                object._y = Stage.height + object._height;
        } else if (topBorder >= Stage.height) {
                object._y = initY;
        }
}


In this code you can use Degree angles and then convert them to radians.
This will give you some kind of asteroids game type of motion.

HTH


Alain
-----Original Message-----
From: Kevin Aebig [mailto:[EMAIL PROTECTED] 
Sent: 12 octobre 2006 14:43
To: 'Flashcoders mailing list'
Subject: [Flashcoders] Scripted Angled Motion

Hey all,

 

I'm trying to do something, but the mathematics of it are messing with my
head.

 

I've got a clip that I want to move in a specific direction (angle) without
giving an end target. When the clip is offstage, I'll simply reset it and
trigger it again accordingly. 

 

I don't need for it to ease or anything fancy, just move on a designated
angle.

 

Thanks,

 

!k

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.com


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.2/472 - Release Date: 2006-10-11
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.2/472 - Release Date: 2006-10-11
 

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to