Gw Temp

Tutorial - 'Movement Tutorial' by fishmeester

An item about Gamemaker posted on

Blurb

The basics of movement for Gamemaker!

Body

Speed tutorial version 1.1 for Game Maker version 4.3
by Fishmeester from Summertime Productions

1. Introduction
Speed, what is speed actually? In real life, this is a difficult question.But in GM it seems difficult, but it's very easy.
In GM speed is how much pixels an object moves each step. For example if an object has a speed of 8, this means it moves 8 pixels each step.

2. Constant speed.
This is the easiest use of speed and movement. This uses the red arrows.
First make the event keyboard right. Then drag the red arrows into the tray.Choose the arrow aiming right and set the speed to 6. Then do the same for the left up and down events, each with their respective arrows.
Now to make sure your object stands still if you press no buttons, select the no button event and add a red arrow but select the square in the mid, here the speed does not matter.
Congrats, you now have a walking object.

Now we're going to make it a bit more difficult.
First go to the right event and remove the red arrows.Then add the blue arrows.Set the direction to 0 and the speed to 8.
Do the same with up down and left, with up the dir is 90 with left it's 180 with down it's 270.
Have you found out how it works now? Right is 0 and then the amount of degrees counter-clockwise.

Now to allow easy diagonnal movement.
In the left event add the jump to position action (The X connected to the X) and set the X position relative to -8 . Do the same with the right event but then positive.
Do the same with the up event but then place it in the y position box. do the same with the down but in positive. Also, remove the no key event.

3. Acceleration.
Now you have an object wich moves at a constant speed. But now go to the blue arrows and set the speed to 1.5. and check the box relative. Do this with all four events.
Then go to no key and place an action called friction an icon with a big and a small green arrows). and set it to 0.5. If you go test it now, you notice that your object goes faster and slowly slows down if you release all keys.
You should also see that he can move diagonnaly.
You can also build in a system that you need to tap the buttons to accelerate do this by changing the events into key press events.

4.Gravity.
Gravity is something you will rarely use in games wich you see from the top, but i will add
a part about it anyway.First, change the speed of the up arrow from 1.5 to 2. then add a create event and drag the 2 blue arrows pointing downwards to it. Set the gravity to 1 and the dir to 270 (the dir is the same as with blue arrows).
Also creat a solid object named wall and add to the collision event of your object collision with wall: reverse vertical direction.
Now just test it.

And now you should be able to make your objects move around OK.