> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/gui/cursor/worldx.md).

# WorldX

### Introduction

The WorldX property returns the X coordinate of the cursor in world units (impacted by zooming and camera position). WorldX is typically used on 2D games, or 3D games where the Z=0 plane contains the entities. For 3D games, see the [WorldXAt method](/flatredball/api/flatredball/gui/cursor/worldxat.md).

### Code Example - Moving an Entity with the Cursor

The following code shows how to move an entity instance with the cursor.

```
// This example assumes a Screen which contains PlayerInstance
void CustomActivity(bool firstTimeCalled)
{
  var cursor = GuiManager.Cursor;
  PlayerInstance.X = cursor.WorldX;
  PlayerInstance.Y = cursor.WorldY;
}
```

### Code Example - Moving an Entity towards the Cursor

The following code shows how to move an entity instance towards the cursor.

```
var cursor = FlatRedBall.Gui.GuiManager.Cursor;

if(cursor.PrimaryDown)
{
    var cursorPosition = new Vector3(cursor.WorldX, cursor.WorldY, 0);
    var directionToPlayer = cursorPosition - PlayerInstance.Position;
    var normalized = directionToPlayer.NormalizedOrZero();
    float movementVelocity = 60;

    PlayerInstance.Velocity = normalized * movementVelocity;
}
else
{
    PlayerInstance.Velocity = Vector3.Zero;
}
```

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-96fde187f2a2ebe095fa0d4940baf3bd69ee3722%2F2021-07-19_08-21-23.gif?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/gui/cursor/worldx.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
