FrozenHaddock Tutorials: 8 Way Movement

In this tutorial, we're going to create simple, 8-way, top-down movement. This is easy to implement and effective to use.

car
First, draw what you want to move.
You need to draw it facing upwards for the rotation to work.

carselected
Now select your character.

converttof8
Hit F8, and convert the car to a movie clip.

actionspanel
Open the actions panel for the car.
To do this, select the movie clip and hit F9.

ActionsOne
Now, this script creates the 8 way movement.
Unfortunately, this doesn't make the character rotate.

longerscript
This needs to be added into the previous script.

rotatescript
And lines need to be added into the existing script.

So, the full script you have on there should be this-

onClipEvent(load){
speed=5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)&&Key.isDown(Key.UP)){
this._x-=speed;
this._y-=speed;
this._rotation=315;
}
else if(Key.isDown(Key.LEFT)&&Key.isDown(Key.DOWN)){
this._x-=speed;
this._y+=speed;
this._rotation=225;
}
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.UP)){
this._x+=speed;
this._y-=speed;
this._rotation=45;
}
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.DOWN)){
this._x+=speed;
this._y+=speed;
this._rotation=135;
}
else if(Key.isDown(Key.LEFT)){
this._x-=speed;
this._rotation=270;
}
else if(Key.isDown(Key.RIGHT)){
this._x+=speed;
this._rotation=90;
}
else if(Key.isDown(Key.UP)){
this._y-=speed;
this._rotation=0;
}
else if(Key.isDown(Key.DOWN)){
this._y+=speed;
this._rotation=180;
}
}

This should produce this

This can be used in many types of games, particularly RPG's.

 

Written by: TazzyDevil XIII
Website: http://www.frozenhaddock.co.uk