Generate Object at the same height of cursor

Hi Ash,

By default, the ARHitTester.cs script will create an instance of the PlacementObjectPf GameObject at the tapped location.

However, if you’d like to introduce an offset to the instantiated object’s location, you can follow these steps to modify the ARHitTester.cs script.

  1. Navigate to line 122 of the ARHitTester.cs script.

  2. Observe that the Instantiate() method call is taking three parameters…

  • An Object prefab to instantiate
  • A Vector3 for the position to instantiate the GameObject at
  • A Quaternion for the rotation to instantiate the GameObject with
  1. Immediately after hitPosition and before the comma, add a new Vector3(X, Y, Z) to the hitPosition to represent the offset you wish to apply, where X and Z are float values that represent the desired distances along the x and z axes relative to the hit position, and Y is zero (if you wish for the instantiated object to have the same y value as the cursor, as you mentioned in your original message).

In addition to a gray cube instantiated at the hitPosition, the following example image shows…

  • a red cube instantiated 1 unit away from hitPosition along the x-axis
  • a green cube instantiated 1 unit away from the hitPosition along the y-axis
  • a blue cube instantiated 1 unit away from the hitPosition along the z-axis

We hope this helps with modifying the instantiation position of objects spawned with the ARHitTester.cs script!

1 Like