Player Asset

We’ll add an Agent Component so our character can move.

Now that we’ve built the systems we need to incorporate them into the Player entity.

Entities are the objects in our games. Worlds can define Entities. But if we plan to re-use those entities, it’s better to use a Prefab asset.

Luckily, Hello Murder comes with a Player prefab we can use. So we’re going to add components to it.

In this section, we’ll:

  • Add the Player component to the player
  • Add the Agent component to the player

Adding components

  1. Click the Prefabs folder in the Assets tree to expand it.

  2. Now select the Player prefab. The PrefabAsset editor will appear:

    PlayerAsset Editor

  3. The Player already has the three “basic” components:

    • Collider - Keeps the object from overlapping other Collider entities
    • Position - Tracks this object’s position in the world
    • Sprite Component - Contains the “visuals” needed to render the entity onscreen

    We’ll need to add some more components.

  4. Click Select a component and select PlayerComponent from the list.

    The Player component is used by the Player Input system to identify the player to be controlled.

  5. Click Select a component and select AgentComponent from the list.

    Agents are objects that can be moved around by player input. The Agent component stores the properties needed to tell the Agent Mover system how to convert player input into entity movement:

    • Speed - Declares the agent’s maximum speed of an agent
    • Acceleration - Declares how fast the agent can reach maximum speed
    • Friction - Determines if the walking surface is slippery (0.0) or rough (1.0).

    For this demo, try the following settings at first:

    • Set Speed to 50.0
    • Set Acceleration to 20.0
    • Leave Friction set at 0.0
  6. Click Save Asset to save changes to our Player prefab:

    PlayerAsset Editor

Next steps

Now that we’ve updated our player prefab, we’ll play the game and test out our changes.