• 8th December 2008 - By Bill Nunney
    Flash CS3 Professional

    Hello, So i finally dragged myself away from playing even more games (completed Dead Space finally!) to bring you a follow up to my previous tutorial BLAHLINK. This Tutorial will show you how to add forward momentum in the correct direction based on the angle of the movieclip player.

    first download the Source Files from my last tutorial. We will use this as a base.

    Now change the update function as shown here. (edits shown in bold).

    // our update event function
    function update(Event)
    {
    	// updating the position
    	Beans_MC.x += xVel;
    	Beans_MC.y += yVel;
    
    	// applying drag to the velocity
    	xVel *= drag;
    	yVel *= drag;
    
    	// add a rotation to Beans_MC
    	Beans_MC.rotation += 1;
    }

    This is only for testing purposes just to give our test a bit of merit.

    Now the two lines which will add our forward movement.

    edit the same function:

    // our update event function
    function update(Event)
    {
    	// updating the position
    	Beans_MC.x += xVel;
    	Beans_MC.y += yVel;
    
    	// applying drag to the velocity
    	xVel *= drag;
    	yVel *= drag;
    
    	// add a rotation to Beans_MC
    	Beans_MC.rotation += 1;
    
            // calculate new velocity values based on the angle (rotation) on the target movieclip
    	xVel = -(3 * Math.cos(Beans_MC.rotation * Math.PI/180));
    	yVel = -(3 * Math.sin(Beans_MC.rotation * Math.PI/180));
    }

    Now test your movie!

    Amazing! its moving round in a circle!

    Thats it! try tweaking the values to get different results. You could even tie these up to button presses to make a controllable ship (hint hint).

    Bye!

    Also here are my edited source files…

  • Leave a Reply