vspeed (Game Maker)

## vspeed

vspeed - vertical speed of an instance.

## Description

vspeed is a local variable that contains the current vertical speed of a an instance, in pixels per step. A negative vspeed will cause the instance to move up and a positive vspeed will cause the instance to move down.

## Examples

### Example of Use

````vspeed = 1;`
```

In this example, the instance will move 1 pixels down every step.

### Limiting vspeed

``````if(vspeed > 20)
{
vspeed = 20;
}
if (vspeed < -20)
{
vspeed = -20;
}```
```

If this is placed in a Step event, it will limit an object's vspeed to 20. See threshold.

### Jumping

From a game design perspective, jumping in a platform game is nothing more than setting the vspeed to a negative number so that the player object starts to move upwards. Eventually, gravity overcomes the initial vspeed, and the object starts to fall down.

``````gravity = 0.2;
if(keyboard_check(vk_space)){
vspeed = 5;
}```
```

### Detecting Up/Down Movement

``````if(vspeed = abs(vspeed))
{
//instance is moving down
}
else
{
//instance is moving up
}```
```

The code in this example will tell you if an instance is moving up or down during runtime.

## Reversing vspeed

You can reverse the vspeed by multiplying it by -1. Note that 1 is the identity element of multiplication.

````vspeed = vspeed * -1;`
```

## Useful Info

• direction, if it is not set manually, is calculated by using the vspeed and hspeed of an object. If the hspeed and vspeed of an object is , then direction will be "calculated" to . This causes a few problems as is right, not "no direction".
• Changing an object's x/y-position is considered "teleporting" by Game Maker and will not influence or change vspeed.

## Related Pages

### Variables

• direction - the direction an object is moving, in degrees.
• speed - an objects speed in relation to direction.
• hspeed - the horizontal equivalent of vspeed

### Actions

page revision: 18, last edited: 11 Jan 2014 02:45