Moving

From Game Editor

Revision as of 12:21, 11 September 2010 by Skydereign (Talk | contribs)
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.


Example:

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.


Example:

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.


Example:

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.


Example:

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