# Creating the Puck Entity

### Introduction

Now that we have our PlayerBall movement working, we'll add a Puck Entity which the user can hit around. You'll find that the Puck is very similar to the PlayerBall.

### Creating a Puck Entity

To create a Puck Entity:

1. Click on the **Quick Actions** tab
2. Click the **Add Entity** button
3. Name the Entity **Puck**
4. Check the **Circle** check box under **Collisions**
5. Verify that **ICollidable** is checked (it should be checked automatically when **Circle** is checked)

   ![Options for creating a Puck entity](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-6fa3adece1e282bd4dae697830f2cef9be0ca6cc%2F2021-07-img_60fdc0904b245.png?alt=media)
6. Click **OK**

The Puck entity should appear in the FlatRedBall Editor.

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

For more information on how to perform the above steps, you may want to review the tutorial which created the [first entity (Player)](https://docs.flatredball.com/flatredball/tutorials/beefball/creating-an-entity).

### Differentiating the Puck

Currently our Puck and PlayerBall both have Circle bodies, and by default the Circles have the same size and color. To differentiate the Puck from the PlayerBall:

1. Expand the **Puck** entity
2. Click on the **CircleInstance** object under the Puck Entity
3. Click the **Variables** tab
4. Find the **Color** variable
5. Change the value to **Red** using the drop-down
6. Change the **Radius** value to **6**

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

**Computer settings matter:** If your computer is set up so the decimal separator is the comma ',' instead of the period '.' then you should enter values using the ',' character. Unlike C# code, Glue obeys your computer's language settings.

### PuckList in GameScreen

By default the FlatRedBall Editor adds lists of newly-created entities to the GameScreen. Therefore, you should already have a PuckList in your GameScreen.

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

If you unchecked the option, or if you would like to know how to manually add a PuckList to your GameScreen, the following section shows how to add a list. **This is not necessary if you kept the defaults.**

### (Optional) Adding a PuckList Manually

1. Click the Puck entity
2. Select the **Quick Actions** tab
3. Click the **Add Puck List to GameScreen** button

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

### Adding a Puck Instance

1. Select the **Puck** entity
2. Under the **Quick Actions**, Click the **Add Puck Instance to GameScreen** button

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

Now the GameScreen has a list and a single Puck.

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

### Positioning your objects

If you run your game you'll notice that the PlayerBallInstance and PuckInstance are both at the center of the Screen. Let's reposition the PlayerBall1:

1. Select the PlayerBall1 object under your GameScreen
2. Change the X value to -180

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

### Puck Collision

Now that we have a Puck in our game, we need to create two collision relationships:

1. Puck vs Walls - this prevents the Puck from moving through the walls.
2. Puck vs PlayerBall - this allows the PlayerBall to "hit" the puck to try to score a goal. We haven't yet created the handling of goals, but this is the first step towards implementing that feature.

We create these two collision relationships just like the previous PlayerListVsWall collision relationship. To create a relationship between the PuckList and Wall:

1. Expand **GameScreen's Objects** folder in Glue
2. Drag+drop the **PuckList** onto the **Walls** object
3. Select the new **PuckVsWalls** collision relationship
4. Select the **Collisions** tab
5. Set the **Collision Physics** to **Bounce**
6. Change the **Puck Mass** to **0**
7. Optionally adjust the Elasticity value

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-2c534fd544cb147ed47f8ff1479bfb085a3ec7da%2F02_07%2008%2047.gif?alt=media" alt=""><figcaption></figcaption></figure>

To create a relationship between the PuckList and PlayerBallList:

1. Expand **GameScreen's Objects** folder in Glue
2. Drag+drop the **PlayerBallList** onto the **PuckList** object
3. Select the new **PlayerBallVsPuck** collision relationship
4. Select the **Collisions** tab
5. Set the **Collision Physics** to **Bounce**
6. Change the **Puck Mass** to **0.3** - this makes it 30% the mass of the PlayerBall
7. Optionally adjust the Elasticity value

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-974cb9f950e6e8e6126442a5063ac0340091fe3d%2F02_07%2021%2014.gif?alt=media" alt=""><figcaption></figcaption></figure>

Notice that the mass variables for PlayerInstance vs. PuckInstance differ compared to wall collision. The PuckInstance is given a mass of .3 relative to a mass of 1 for the PlayerInstance, resulting in the PuckInstance behaving as if it has 30% of the mass of the PlayerInstance. If you run the game, you should be able to hit the Puck around the level.

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-dcb1b739ba1c66a2286bd40be5d0dc26605e9e33%2F2016-01-2021_July_25_140010.gif?alt=media" alt=""><figcaption></figcaption></figure>

### Adding Drag

Currently the Puck moves indefinitely after being hit. We'll assign the Drag value to the Puck just like we did to PlayerBall:

1. Select the **Puck** Entity in Glue
2. Select the **Variables** tab
3. Click the **Create a new variable** button
4. Select the **Expose an existing variable** option
5. Select the value **Drag**
6. Enter a value of **0.4** for **Drag**

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

Now the Puck slows down over time just like the PlayerBall.


---

# 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/beefball/creating-the-puck-entity.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.
