The first thing we need to do now is make the path more elliptical, this gives the impression we are looking from the side rather than top down. This is quite easy to change, just lower the vertical radius. So, replace the line:

PHP Code:

```
_root.mars._y = 200 + Math.sin(radians) * 150;
```

With:

PHP Code:

```
_root.mars._y = 200 + Math.sin(radians) * 50;
```

Press ctrl+enter to check out the changes.

You should notice an error, as the rotating planet is always behind the stationary planet. What we need to do is store whether the rotating planet is on the top or bottom. So, in the main frame, add the line:

PHP Code:

```
_root.mars._onTop = false;
```

Now, here is the next bit of code.

PHP Code:

```
if(_root.mars._x < _root.mars._last && !_root.mars._onTop){
```

_root.mars.swapDepths(_root.sun);

_root.mars._onTop = true;

}

if(_root.mars._x > _root.mars._last && _root.mars._onTop){

_root.mars.swapDepths(_root.sun);

_root.mars._onTop = false;

}

_root.mars._last = _root.mars._x;

It is a little confusing but basically what it does is this. It stores the last place x was, then compares it to where x is this time. If x changes direction, it swaps depths and changes the _onTop property.

Almost done! Next we need to change the size of the planet. To do this we will find the distance of the planet from the center. When the planet is close to the center, it is either going to be very large or very small. As it moves away from the center it will be closer to the base size. So, lets first find the offset:

PHP Code:

```
var offset = (182-(Math.sqrt(Math.pow(_root.mars._x-200, 2)+Math.pow(_root.mars._y-200, 2)))) / 5;
```

182 is the farthest it can be away from the center, so the greater the distance away, the small the offset. The bulk of the code (Math.sqrt(Math.pow(_root.mars._x-200, 2)+Math.pow(_root.mars._y-200, 2))) is just the distance formula. Remember, the distance formula is:

D = sqrt ( (X1 - X2)^2 + (Y1 - Y2)^2 )

It is divided by 4 at the end to make the results less extreme. To increase the illusion of depth, the number can be lowered.

So, now we have our offset, but what we do with it depends on whether our planet is on top or on bottom. This line will add it to the height and width if _onTop is true, subtract it if false. Notice that the 50 in this line in the base size of the object.

PHP Code:

```
_root.mars._height = _root.mars._width = _root.mars._onTop ? 50 + offset : 50 - offset;
```

**Note : this formula does have a slight error, as size should increase more towards the outside. Works good enough, feel free to suggest better formulas.**

The last thing left is to add a diagonal slant to the orbit path. To do this, just add (Math.cos(radians) * 100) to the y coord. This way when the planet in on the left side, it is higher than on the right.

Anyway, that is basically it. Feel free to add space ships, asteroids, collision detection, whatever. Feel free to ask any questions or comments. Please realize this was my first tutorial, so, be nice Also, would anyone be interested in a tutorial on dynamically creating objects and making a particle engine? How about making and using sounds? Simple collision detection?

Anyway, that is it, download the fla file for a final version.

Trent