3D Maths Help

Key Points

-Making a DJ App
-Need to alter
-Maths is hard

public float SliderValue() {

		if (isPitch) {

			float distAlongForward = Vector3.Dot(transform.position - originalPosition, -transform.forward);
			distAlongForward /= m_pitchRange;
			return distAlongForward;

				}

		else {
		float distAlongForward = Vector3.Dot(transform.position - originalPosition, -transform.right);
		distAlongForward /= m_range;
		return distAlongForward;
		}
	}

  • So I presumed I use transform.forward as to measure against the Z axis as the slider goes towards and away from the user (who is pulling and pushing using leap motion).

  • If that is correct, what exactly should the range relevant to in order to make this a manageable number.

  • I then need this number to affect the pitch (i.e. convert this output number into a number between 0.5 (half speed) and 2 (double speed) to alter the pitch.

In Summary: Output number from DOT function → range that outputs nicer number? → convert so if more than 0 multiply towards 2 and if less than 0 multiply towards 0.5.

If anything is not explained well please ask as this is University urgent :stuck_out_tongue:

To be honest, I have no clue what you are trying with your dot product, but you could make everything easier with a second gameobject.
Make your slider a child object of your new gameobject and set local position and rotation to zero, rotate and position your parent to the desired position and move only the child object . Slider value will be slider.transform.localPosition.z, if you moved your slider 20 cm, slider.transform.localPosition.z will be 0.2f