Generate Object at the same height of cursor

Hello guys I am trying to generate Gameobject at the same y of ARHitTester’s cursor with the different x and z
I set the y of the cursor for the generated objects and they are not going to stand at the same height as the cursor when the cursor is near to the ground or at the same height as the ground
also when I move the phone on the y-axis objects’ height change relatively with phone movement

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