From Game Editor

Jump to: navigation, search

In gameEditor, there are several ways to achieve movement of an actor. Which method to use depends on what you prefer and the type of actual movement you want, such as sliding. For those new to gameEditor and computers, the y-axis is flipped, so up is negative, and down is positive. Here are the 6 ways to achieve movement in your game.

  • x and y manipulation
  • xvelocity yvelocity
  • angle and directional_velocity
  • MoveTo
  • Paths
  • vectors

x and y manipulation

For a simple platformer, this is usually the way to go. The caveman tutorial that comes with gameEditor uses this method, as it is short and to the point. All you need to do is alter the actor's x or y coordinates through math.


player -> KeyDown Right (repeat enabled) -> Script Editor

x = x + 5;

What this script does is while key right is being pressed, move the player 5 pixels to the right. To change speed of the player, all you need to do is replace the +5 with any other value. Inserting -5 will make the player move left instead of right. The trick to this method for constant movement is that the event must be repeating constantly. Though this example shows constant movement, it can also be used to place actors to certain locations. So if you wanted to move the view to the next level after colliding with a door, you would do something like this.


player -> Collide with Door (repeat disabled) -> Script Editor

view.x = 500;
view.y = 100;
x = 800;
y = 200;

This will move the view to point (500,100), and the player to (800,200) upon the collision with the door actor.

xvelocity and yvelocity

Manipulating x and y using basic math equations will work a lot of the time, but can be not as efficient or simply not what you want. This method also requires script editor, and knowledge of basic math syntax in C. The idea behind these velocity variables is that you can set the variable once, and every frame the actor will move according to the values of xvelocity and yvelocity.


enemy -> Create Actor -> Script Editor

xvelocity = -5;

By setting xvelocity to -5 the enemy will constantly be moving the the left at -5 pixels per second. If you were to use the previous method to do this, you would have to use the Draw event, which should be avoided if unnecessary.

Unlike setting x and y, the velocity variables allow for accelerating/decelerating, and sliding. If you wanted the player to accelerate to the right while you press right, instead of move at a constant speed, you can do something like this.


player -> KeyDown Right (repeat enabled) -> Script Editor

xvelocity = xvelocity + 0.2;

When dealing with velocity variables, it is best to use smaller numbers, as you will find that the player will increase speed extremely fast. With a fps of 30 you will quickly find that adding 1 will result in lighting speed. Here is another example which sets a max speed, in this case 10, that the player can accelerate to. player -> KeyDown Right (repeat enabled) -> Script Editor

xvelocity = min(xvelocity+0.2,10);

angle and directional_velocity

Similar to using xvelocity and yvelocity, directional_velocity does not need to be reset each frame to have movement. The difference though is that directional_velocity allows you to move the actor in directions according to the actor's angle. This can be achieved by using xvelocity, yvelocity, and trig, but this way is much simpler. If you want your bullet actor to move at a 45 degree angle with a speed of 10, all you need to do is set the variables like this.

bullet -> Create Actor -> Script Editor


While this could pretty easily be done by using xvelocity and yvelocity, this method does not require trigonometric computations and allows you to directly see the speed.

One thing to watch out for when dealing with this method is that if the directional_velocity is ever zero, the angle will reset itself. To prevent this you would have to set the actor's real angle variable with your own.

bullet -> Draw Actor -> Script Editor


Another benefit for using this method is you can create circular movement. Increasing directional_velocity and angle in draw will make your actor spiral outward. You can also use the angle and directional_velocity with the direction function to create homing objects.