smokiespartakus
smokiespartakus

Reputation: 176

tween to other moving object in AS3

Is it possible to move one object towards another that might be moving?

I can only put x,y coords as moving parameters as far as I can see(?)

Upvotes: 0

Views: 295

Answers (1)

user1622998
user1622998

Reputation:

without using greensock you could do the following as a basic example:

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void{
    if(object1.x<object2.x){
        object2.x-=5;
    }else{
        object2.x+=5;
    }

    if(object1.y<object2.y){
        object2.y-=5;
    }else{
        object2.y+=5;
    }
}

Greensock animation requires a duration meaning the tween will come to an end at some point. There is a dynamicprops plugin but that also comes to an end eventually so this have to be done manually for any long amount of time.

Implementing basic friction and/or gravity will add to the realism (multiplying the '5' number by a friction amount for example).

Upvotes: 4

Related Questions