Basics of Circular Motion

Index

Attached Files

The following files have been attached to this tutorial:

.capx

circularmotion.capx

Download now 189.1 KB

Stats

2,964 visits, 6,896 views

Translations

This tutorial hasn't been translated.

Tools

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.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!