# Restrict Trajectory on Z axis

I have a cube which I select on mouse and point out the location to throw the cube with trajectory dots.

The code is working fine, but I need to restrict the trajectory dots position on z axis so the user could not be able to throw it towards z axis.

Here is my code

   if (cubePlane.Raycast(camRay, out enter))
{
cubeisClicked2 = true;
fingerPosition = camRay.GetPoint(enter);

cubeFingerDiff = cubePosition - fingerPosition;
ShotForce = new Vector3(cubeFingerDiff.x * shootingPowerX, cubeFingerDiff.y * shootingPowerY, 0);
if (cubeFingerDiff.magnitude > 0.4f)
{
trajectoryDots.SetActive(true);

}
else
{
trajectoryDots.SetActive(false);
}

for (int dotNumber = 0; dotNumber < NumberOfDots; dotNumber++)
{
x1 = cubePosition.x + ShotForce.x * Time.fixedDeltaTime * (DotSeparation * dotNumber * dotShift);
y1 = cubePosition.y + ShotForce.y * Time.fixedDeltaTime * (DotSeparation * dotNumber * dotShift) + (Physics.gravity.y / 2f * Time.fixedDeltaTime * Time.fixedDeltaTime * (DotSeparation * dotNumber + dotShift) * (DotSeparation * dotNumber + dotShift));
z1 = cubePosition.z + ShotForce.z * Time.fixedDeltaTime * (DotSeparation * dotNumber * dotShift);
Dots[dotNumber].transform.position = new Vector3(x1, y1, 0f);
}
}
}


I set the z axis to zero every where but still able point towards z axis.

Note: It is 3D game not 2D

• try cubeFingerDiff.z = 0 after cubeFingerDiff = cubePosition - fingerPosition; – Mohammad Zamanian Jun 2 at 14:13
• you may see I use z as 0 in the following code ShotForce = new Vector3(cubeFingerDiff.x * shootingPowerX, cubeFingerDiff.y * shootingPowerY, 0); – Engr Umair Jun 2 at 15:25