> 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/math/geometry/polygon/collideagainstmove-and-attachments.md).

# CollideAgainstMove and Attachments

### Introduction

Due to the popularity of the [Entity pattern](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), it is very common to have shapes attached to other [PositionedObjects](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). Because of this common setup, all shapes have special behavior in their collision methods to reposition or change the velocity of their [TopParent](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### The Attachment Hierarchy

The attachment hierarchy is a collection of [IAttachables](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) and their attachments - or child/parent relationships - which define which objects control the position and rotation of other objects. The following shows a typical attachment hierarchy for an [Entity](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

![AttachmentHierarchy.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-142c2060f99a97d09ec255e72ff50b56ec5475ba%2Fmigrated_media-AttachmentHierarchy.png?alt=media)

In this hierarchy the entity itself is considered the "root" or [TopParent](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). This means that by default absolute changes to position and rotation will affect ONLY the root object. In other words, if the VisibleRepresentation's X is changed in code, the change will not be drawn or persist next frame. To change the VisibleRepresentation's absolute position or rotation, code must either change the root's absolute values, or the relative values of the VisibleRepresentation.

This characteristic is not unique to [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) - it applies to all [IAttachables](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) including all shapes.

### Shapes and the Attachment Hierarchy

Methods like CollideAgainstMove and CollideAgainstBounce are commonly used to prevent overlapping and modify velocity in response to collisions. CollideAgainstMove modifies the absolute Position of the calling shape and the shape it is colliding with to prevent overlapping. CollideAgainstBounce prevents overlapping just like CollideAgainstMove, but also modifies the velocity of the two shapes involved.

This may seem to present a problem; shapes have their absolute properties modified through the CollideAgainstMove and CollideAgainstBounce methods; however, as shown in the entity pattern above, shapes are often not at the root of the attachment hierarchy. Therefore it would seem as if these methods will only work when the shapes involved are the roots of their respective attachment hierarchies.

Fortunately, this is not the case. Since shapes are often children of other [IAttachables](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), any modification to position or velocity gets "pushed up" to the root of the attachment hierarchy.

![CollisionMethodModifications.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-a992d74b3a65f1f9fcc35540630a779dc927369c%2Fmigrated_media-CollisionMethodModifications.png?alt=media)

### Shared Root Conflicts

As mentioned above, the CollideAgainstMove and CollideAgainstBounce methods will update the root's absolute properties. However, if two shapes share the same root, the collision methods will not be able to reposition the objects properly. The following image shows the conflict:

![CollideAgainstMoveConflict.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-4a2074b9946c658c02af94772875d2be9d4adb86%2Fmigrated_media-CollideAgainstMoveConflict.png?alt=media)

Notice that in this situation both children will be modifying the parents' property. However, the parent's absolute values control the absolute values of the attached shapes.

In these situations the regular CollideAgainst methods will work correctly, but the Move and Bounce versions of the method will not be able to properly modify values. Keep this in mind if you are using a shared root for multiple shapes.


---

# 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/math/geometry/polygon/collideagainstmove-and-attachments.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.
