I suck at math please help

Ok so Ive forgotten all my H.S. Geom

I have this code that will move a single object in a spiral trajectory toward the center of the screen


setInterval(MoveBall,30)
function MoveBall(){
    if(myCounter > 0){
        myCounter--
    }else if(myCounter < 0){
         myCounter++
    }

    var angleEnd:Number = 180
    var angleStart:Number = myCounter
    var angleSteps:Number = 100
    var centerX:Number = 200
    var centerY:Number = 250


    simpleSpiralXY = function(inAngle){
    return inAngle/2;
    }    
    
    var aStep:Number=(angleEnd-angleStart)/angleSteps;
    var curAngle:Number=angleStart;


    
   this_mc._x =centerX+simpleSpiralXY(curAngle)*Math.cos(curAngle*Math.PI/180);

    this_mc._y = centerY+simpleSpiralXY(curAngle)*Math.sin(curAngle*Math.PI/180);
    
    curAngle+=aStep

and it works like a champ…but the problem is i need to move several objects in a spiral towards the center of the screen

so i need to incrementally step x,y instead of dirrectly assigning em
instead of …_x= # i need …_x += #
hehe and i just cant figure out the formula

I have some code stolen from an anonymous source:pa:, I feel it will really benefit you:

function setBrightness(col:Color, brightness:Number):Void {
	var anum:Number = 100-brightness;
	var bnum:Number = 255/100*brightness;
	col.setTransform({re:anum, ga:anum, ba:anum, rb:bnum, gb:bnum, bb:bnum, aa:100, ab:0});
}
var scaleMax:Number = 800;
var fadeOut:Number = 0.93;
var frequency:Number = 10;
var colMin:Number = 0;
var colMax:Number = 40;
var colVariance:Number = colMax-colMin;
function hRad(Void):Number {
	return 4+Math.random();
}
function vRad(Void):Number {
	return 4+Math.random();
}
function vRadInc(Void):Number {
	return 0.1;
}
function hRadInc(Void):Number {
	return 0.1;
}
function lrSpeed(Void):Number {
	return 5+Math.random()*40;
}
function scaleUpSpeed(Void):Number {
	return 1.02;
}
function nooCol(Void):Number {
	return colMin+Math.random()*colVariance;
}
var depth:Number = 0;
onEnterFrame = function () {
	if (Math.floor(Math.random()*frequency) == 0) {
		depth++;
		var noo:MovieClip = _root.attachMovie("ball", "ball"+depth, depth);
		var col:Color = new Color(noo);
		setBrightness(col, nooCol());
		noo._x = -50;
		noo._y = -50;
		noo._xscale = noo._yscale=10;
		noo.scaleSpeed = scaleUpSpeed();
		noo.lrSpeed = lrSpeed();
		noo.hRad = hRad();
		noo.vRad = vRad();
		noo.hRadInc = hRadInc();
		noo.vRadInc = vRadInc();
		noo.lr = 0;
		noo.onEnterFrame = _root.expand;
	}
};
function expand() {
	this.lr += this.lrSpeed;
	this.hRad += this.hRadInc;
	this.vRad += this.vRadInc;
	this._x = Stage.width/2+this.hRad*Math.sin(this.lr*Math.PI/180);
	this._y = Stage.width/2+this.vRad*Math.cos(this.lr*Math.PI/180);
	this._yscale = this._xscale *= this.scaleSpeed;
	this.swapDepths(Math.floor(this._xscale));
	if (this._xscale>_root.scaleMax) {
		this._alpha *= _root.fadeOut;
		if (this._alpha<3) {
			this.removeMovieClip();
		}
	}
}

I would have a read over that, it may give you some inspiration in the right direction.:slight_smile:

sweet thanks man…checking it out now

np:flower:

well i messed around a lot with that code…Its pretty awesome…

unfortunatly it still doesnt provide me with a

_x += # instead of _x = #
type of equation for movement

I can prolly tweak it to do what i want…but it would be awesome if anyone out there had a += formula i could get :stuck_out_tongue:

edit im 90% sure i can get this code to do what i need though…im figuring out what to manipulate

is there anyway to corect the way that objects circle faster on the outside of the spiral

here ill post my FLA
see how theres huge gaps on the outside and they get all bunched up inside?
I want to keep uniform distance throughout the spiral

im talking about the horizontal bunching not the vertical…i can fix the vertical but the horizontals gonna need some math to control speed

yeah, that’ll be fun. I’m not sure where to point you, that seems like quite a bit of a pain.

basically what i want to do is have it like a static movie clip and the next movie clip pushes the first one in the path of the spiral…like htey were solid objects that couldnt overlap

[edit] This is my code in its entirety atm(as commented as i could make it)


stop()
var myCount = 1
/*
function setBrightness(col:Color, brightness:Number):Void {
    var anum:Number = 100-brightness;
    var bnum:Number = 255/100*brightness;
    col.setTransform({re:anum, ga:anum, ba:anum, rb:bnum, gb:bnum, bb:bnum, aa:100, ab:0});
}*/

var scaleMax:Number =2500; //Max Scale
var fadeOut:Number = 0.93; //Fadeout(think i made it useless by removing setBrightness...but meh
var frequency:Number = 10; // frequency of ball release(somewhat randomized
var colMin:Number = 5; // ??????
var colMax:Number = 10; // ??????
var colVariance:Number = colMax-colMin; //???????


var hRad:Number = 400.25 //Horizontal radius
var vRad = 400.25 //Vert Radius

var vRadInc:Number = -0.8 //these control how quickly the objects spiral in/ out
var hRadInc:Number = -0.8 // a neg number will spiral in a pos num will spiral out


function lrSpeed(Void):Number {  //
    return 1+1.98953*1;
}
function scaleUpSpeed(Void):Number {
    return 1;
}
function nooCol(Void):Number {
    return colMin+0.1573*colVariance;
}
var depth:Number = 0;
onEnterFrame = function () {
    myCount++
    if (depth == 0 || _root["ball"+depth]._x < 670) {
        depth++;
        var MC_toAttach:String = AssignMovie()
        var noo:MovieClip = _root.attachMovie(MC_toAttach, "ball"+depth, depth);
        var col:Color = new Color(noo);
        //setBrightness(col, nooCol());
        noo._x = -150;
        noo._y = -150;
        noo._xscale = noo._yscale=100;
        noo.scaleSpeed = scaleUpSpeed();
        noo.lrSpeed = lrSpeed();
        noo.hRad = hRad;
        noo.vRad = vRad;
        noo.hRadInc = hRadInc;
        noo.vRadInc = vRadInc;
        
        noo.lr = 0;
        noo.onEnterFrame = _root.Spiral;
    }
};
function Spiral() { //this is the function thats in each clips on enter
                    //It Moves the clip in a spiral
    this.lr += this.lrSpeed  // LR has something to do with speed
    this.hRad += this.hRadInc;
    this.vRad += this.vRadInc;
        //this code just figures out what ball were moving not used atm
        stringtoparse = String(this)
         parsedstring = stringtoparse.split("ball")
        thisindex = Number(parsedstring[1]);
        
    
        // this places the object
    this._y = 300+this.hRad*Math.sin(this.lr*Math.PI/180); 
    this._x = 300+this.vRad*Math.cos(this.lr*Math.PI/180);
}
function AssignMovie(){
    return "Catseye_grn"
}

and this is the SWF in its current form

just seeing if anyone in the monday morning crowd has any ideas on how i can alter my code to gradually speed up the objects movement as it gets closer to the center so it doesnt bunch up like that

maybe like this?

function Spiral() { //this is the function thats in each clips on enter
                    //It Moves the clip in a spiral
    this.lr += this.lrSpeed  // LR has something to do with speed
	
    this.hRad += this.hRadInc;
    this.vRad += this.vRadInc;
	 this.hRadInc*=1.001
	 this.vRadInc*=1.001
        //this code just figures out what ball were moving not used atm
        stringtoparse = String(this)
         parsedstring = stringtoparse.split("ball")
        thisindex = Number(parsedstring[1]);
        
    
        // this places the object
    this._y = 300+this.hRad*Math.sin(this.lr*Math.PI/180); 
    this._x = 300+this.vRad*Math.cos(this.lr*Math.PI/180);
	if(Math.abs(this._x-300)<1 && Math.abs(this._y-300)<1){
		this.removeMovieClip()
	}
}

thanks for the sugestion…unfortunatly it didnt fix it

heres my WIP so far (Spirals1)
spirals2 has your amendment added

(the only thing i changed was
this.hRadInc*=1.001
this.vRadInc*=1.001
)
Spirals1.swf = my current one(I want the spiral like this but i dont want the balls to bunch up at center)

spirals2.swf = my current code with suggested amendmant

[edit] it wont let me post other attach for some reason…but it doesnt stop the overlap just changes the shap of the spiral basically

maybe change the frequency at which you are creating mcs?

mi = setInterval(function () {
	myCount++;
	if (depth == 0 || _root["ball"+depth]._x<670) {
		depth++;
		var MC_toAttach:String = AssignMovie();
		var noo:MovieClip = _root.attachMovie("MC_toAttach", "ball"+depth, depth);
		var col:Color = new Color(noo);
		//setBrightness(col, nooCol());
		noo._x = -150;
		noo._y = -150;
		noo._xscale = noo._yscale=100;
		noo.scaleSpeed = scaleUpSpeed();
		noo.lrSpeed = lrSpeed();
		noo.hRad = hRad;
		noo.vRad = vRad;
		noo.hRadInc = hRadInc;
		noo.vRadInc = vRadInc;
		noo.lr = 0;
		noo.onEnterFrame = _root.Spiral;
	}
}, 500);

I messed with that a bit before i posted…It wasnt helping but ill try some other stuff once i get home from work in 8 hours

bassically what would be ideal would be if everytime a MC was created all the previous MC’s would be pushed forward along the trajectory(like if the circles were solid objects)

(like
Create 1_mc at 30,35
create 2_mc @ 30,35 (push 1_mc to 60,35)
create 3_mc @ 30,35(push 1_mc to 90,35 ; push 2_mc to 60,35)
(each cycle is MC._x +=30 )

would move them in a straight line

So almost like hittest each other?

Yeah exactly like hitTest each other…but it gets all choppy if i add
[AS]
if(!this.hitTest(_root[“ball” +(thisindex - 1)]){ // check to make sure its not coliding with the ball in fron before moving
this._y = 300+this.hRadMath.sin(this.lrMath.PI/180);
this._x = 300+this.vRadMath.cos(this.lrMath.PI/180);
}

[/AS]

and the motion just looks like crap and gets all jerky when they start hitTesting

I think its cause the Object I want to hittest is a circle(but hittests always register as squares…)

Im just getting frusterated with getting my balls to act the way i want(heh that sounds bad)

leave your balls out of this.:smiley:

Bah I cant figure out how to make it spiral(I still really really want the spiral so i made it a box using the following(****ty code)


    if(this._x < 630 && this._y == 50){this._x += speed; }
    else if(this._x == 630 && this._y < 600){this._y += speed}
    else if (  this._x > 0 && this._y == 600){this._x -= speed;}
    else if (this._x == 0 && this._y > 120){this._y -=speed}
    else if ((this._x < 560) && (this._y == 120)){this._x +=speed}
    else if (this._x ==560 && this._y < 530){ ; this._y += speed}
    else if((this._x > 70) && (this._y == 530)){this._x -= speed}
    else if (this._x == 70 && this._y >190){this._y -= speed}
    else if ( this._x < 490 && this._y == 190){this._x+=speed}
    else if (this._x == 490 && this._y  140 && this._y == 460) {this._x-=speed}
    else if (this._x == 140 && this._y > 260){this._y-=speed}
    else if (this._x < 420 &&this._y ==260){this._x +=speed}
    else if (this._x ==420 && this._y < 390){this._y+=speed}
    else if (this._x > 210 && this._y == 390) {this._x-=speed}
    else if (this._x == 210 && this._y > 340){this._y-=speed}
    else{
    
    this._x += Math.random()
    ; this._y += Math.random()}
    
    

If anyone knows of a better way to do this please please please tell me

anyway here is what i wanted the spiral to look like …if i could have gotten it right