Mobile

Designing for Mobile

Horizon Creator Academy

Hands-On Challenge: Designing for Mobile

Hands-On Challenge Overview

This challenge shows how to set up aim assist for your mobile world. Aim assist makes aiming easier for mobile players as it can be difficult for precise aiming. Aim assist also balances the playing field against web and VR users.
You’ll learn how to:
  • Get aim assist targets.
  • Set aim assist targets.
  • Clear aim assist targets.
Estimated Time: 1 hour

What You'll Need:

  • Windows PC
  • Access to the Worlds Desktop Editor
  • Visual Studio Code or preferred IDE

Challenge Steps:

1. Place “Pistol” Public Asset
  • Open the public asset library.
  • Select MetaHorizon from the Creator drop down box.
  • Select Interactive from the All drop down box.
  • Type Pistol in the search bar.
  • Drag the Pistol asset into the world.
2. Place Targets Throughout the World
  • Select Shapes from the Build drop down box.
  • Drag a cube into the world.
  • Add a tag called “Target” to the cube.
  • Duplicate the cube several times placing each in a different location.
3. Aim Assist Setup
  • Open the Gun script in your preferred IDE.
  • Create a variable of type Entity[].
  • Create a variable of type number and set it to the desired max distance i.e. 50.
  • Set the variable to the targets with the getEntitiesWithTags() method.
  • Create a new method called FindClosesTarget.
  • Call this method in the Start method if the owner is not the server player.
  • Add a check to ensure the player is on a Mobile device.
4. FindClosesTarget:
  • Cache the array of targets.
  • Cache the gun owner.
  • Create (let) a variable of type Entity.
  • Create (let) a variable of type number and set it to Number.MAX_VALUE.
  • Iterate through the array of targets
    • Create (const) a variable and set it to the distance between the gun and the current target in the array.
    • Check if this value is less than the variable created in step 4.d.
    • If so:
      • Set the variable created in step 4.c to the current target in the array.
      • Set the variable created in step 4.d. To the distance.
  • Check if a target was selected
    • If not:
      • Clear the players aim assist target.
    • If so:
      • Set the players aim assist target to the target.
  • Create a timeout delay of 1 second.
5. Publish the World & Test on Mobile:
  • Aim assist does not work in the editor or in preview mode.
  • Aim assist only affects Mobile devices. But the code will still run. This is why we check for device type.

Level Up:

  • Add code to only check for the closest object that you are looking at.
  • Experiment with the AimAssistOptions.

Need Help?

Related Links