Nathan
Nathan

Reputation: 536

How to make object follow another objects tween path AS3

So I have an object named player which the user controls with touch events. There is another object called vine that swings back and fourth by tweening the object in Flash CS6 not by using any code.

What I'm trying to accomplish is when the user pushes the jump button and the player hittests the vine, I want the player to be attached to the vine and follow it's tween path. I accomplished everything except for the player object actually being attached to the vine and swinging with it.

Here is the code I wrote, when I execute it and the player comes in contact with the vine, the player does snap to the vine at the vine's position, but not following the tween path, it just gets stuck and I can't control it anymore.

private function checkPlayerHitVine():void 
{
    if (player.hitTestObject(vine))
    {
        trace("Player Hit Vine");
        player.x = vine.x;
        player.y = vine.y;
    }
}

Please if you can give any help or examples I would really appreciate it. Thanks for your time!

Upvotes: 0

Views: 744

Answers (1)

dan-steel
dan-steel

Reputation: 345

A crude way of doing it would be to add a 'handle' (DisplayObject) on the vine that matches the swing on the vine (it could be transparent), then, on contact, the player's x and y could match the handle's x and y. It would be attached to the vine in the same position despite where the collision was though. Maybe you could put 'high' and 'low' handles...

Upvotes: 1

Related Questions