# Basics of Circular Motion

2
• 30 favourites

### Attached Files

The following files have been attached to this tutorial:

.capx

### Stats

5,994 visits, 12,341 views

### Translations

This tutorial hasn't been translated.

## Coding

First of all we'll need to add one or more avatars to our game field. Then, we must add the Rotation (rot) and Speed (spd) instance variables to the avatar. If you don't know how to add instance variables, check this page in Construct 2 Manual.

After that we must define the Speed of our avatar. Don't worry about the Rotation since it will be calculated afterwards.

### Controlled Motion

In this section we will describe how to implement an avatar that moves in circular motion whenever players press the keyboard arrows. We'll use the cute little moons for that.

Let's see how it works line by line!

In this line, which runs once at the beginning of the Layout, we calculate the rot for every moon. If your game has variable speed, that is, the spd of an avatar changes, you should put that into a Function and recalculate rot every time you change the spd.

If you want to see a detailed explanation about the equation used to calculate rotation, check the last page of the tutorial. It's quite complicated and some people just want to make it work no matter how, so, I left it to the end. :)

The rest of the code just checks if the arrows are pressed and move the avatar clockwise or counter-clockwise. Avatar are rotated rot degrees and move spd pixels per tick and that's what these lines are doing: rotating the avatar and moving it at the new angle.

### Automatic Motion

In this section we will describe how to implement an avatar that moves in circular motion automatically without player interference. We'll use the devilish little moon that refuses to receive orders from puny humans for that.

Automatic motion avatars have the same instance variables, but their actions are triggered by a Every Tick System Condition.