For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

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

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.

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);
}
Player1 moving when space is held.

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.

Player moving around with a GroundVelocity.X value set to 32

Last updated

Was this helpful?