# GroundVelocity

### Introduction

The GroundVelocity property is used to simulate the ground moving under the player. By default GroundVelocity is a 0-length vector which means the player is not standing on moving ground.&#x20;

GroundVelocity can be set for the following reasons:

* Simulating standing on moving ground such as a treadmill or moving walkway
* Standing on a moving platform such as log floating on a river
* Being pushed by the environment such as standing in blowing wind or flowing water

{% hint style="warning" %}
GroundVelocity is a Vector3 for convenience when applying velocity, but only the X and Y values should be assigned. Setting the Z value results in the entity's Z value changing which can affect ordering or even move the entity out of the camera's minimum and maximum Z values.

In other words, be sure to keep GroundVelocity.Z set to 0.
{% endhint %}

### Code Example - Setting Ground Velocity

GroundVelocity can be set per instance. For example, the following code sets the GroundVelocity on Player1 when the Space bar is held down.

```csharp
if(Keyboard.Main.KeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
{
    Player1.GroundVelocity = new Vector3(32, 0, 0);
    EditorVisuals.Text("Space is held", Camera.Main.Position.AtZ(0));
}
else
{
    Player1.GroundVelocity = new Vector3(0, 0, 0);
}
```

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2FzFfhSThqwGRqhXGsfLFw%2F14_13%2037%2053.gif?alt=media&#x26;token=c6f04bff-3e6a-409b-95fb-a8b060c64f00" alt=""><figcaption><p>Player1 moving when space is held.</p></figcaption></figure>

### GroundVelocity Affects Movement

Top down entity movement is performed relative to GroundVelocity. If GroundVelocity is assigned to a non-zero vector, then all movement is performed relative to that new value. For example, if GroundVelocity is set to have an X value of 32, then the entity can move 32 pixels faster on the X axis when moving to the right, and 32 pixels slower when moving to the left.

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2FhXB3Hz2DN8iHwOd6oAMt%2F14_13%2043%2024.gif?alt=media&#x26;token=e2d419d5-5a13-4d05-a479-576de52f331b" alt=""><figcaption><p>Player moving around with a GroundVelocity.X value set to 32</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/flatredball/tutorials/top-down-entity/groundvelocity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
