> 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/camera/attachto.md).

# AttachTo

### Introduction

The Camera class inherits from the [PositionedObject](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) class, so it can use the AttachTo function. For general information on AttachTo, see the [PositionedObject.AttachTo](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) page.

### Attaching a Camera to another object

The simplest way to have the Camera follow an object is to attach the Camera to the object. However, if you do this, you will need to make sure to have the Camera's RelativeZ be a positive value so that the Camera isn't at the same Z value as the object it is attached to. For example, the following code attaches a Camera to a PlayerInstance - which is assumed to be a PositionedObject:

```
SpriteManager.Camera.AttachTo(PlayerInstance, true);
SpriteManager.Camera.RelativeX = 0;
SpriteManager.Camera.RelativeY = 0;
SpriteManager.Camera.RelativeZ = 40;
```

### AttachTo vs. Manual Camera Following

Attaching a Camera to another PositionedObject (like an Entity instance) is the easiest way to have the Camera follow on object; however, it is rather limited in its movement. Most modern, professional games do not attach the Camera to the player. The reason is this results in an unnatural form of movement. Rather, most modern games will do the following:

* Perform smoothing in the movement - often the Camera may lag behind player actions
* Looking ahead towards where the player is facing
* Adjusting to prevent the "end of the world" from being seen
* Scripted movement such as zooming out or moving on game events like when entering a new environment or when a boss appears

Therefore, attaching the Camera to an object is a good initial following implementation, but you should consider replacing this with a more advanced implementation as your game moves further along.


---

# 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/camera/attachto.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.
