Math problem - trying to move GameObject according to various positions of the hand using Leap Motion.

Hi there,

The problem seems simple enough to solve but I cannot wrap my head around how to get it to work.

I have a GameObject, which I want to move from 0 to 12 on the Z axis. I want this to be in accordance with the palm position of the hand.

The hand (for arguments’ sake) moves in a reaching movement from 150 to -150 Leap units (the Leap Z axis is reversed to the Unity Z axis). So I want the GameObject to move from 0 (at 150 Leap units) to 12 (at -150 Leap units).

The stickler is; i need this to be configurable no matter what the two Leap values are. 120 to -20, 200 to 0, 80 to -220, for example.

Can anyone help!?

See if this works:
float leapInput; //the inverted leap input
float leapMax; //The maximum
float leapMin; //The minimum
float leapNorm; //The normalized (0-1) value of leapInput
GameObject myGameObject; //The GameObject you’re trying to move

//This needs to happen every time you get a new value from leap controller
	leapInput = [direct leap input] * -1f //Inverses leap values

//******** Not sure if you meant this had to be defined on the fly or not, but this should do it.
	//Normalize leap values based on min and max
	if (leapInput < leapMin) //min
		leapMin = leapInput

	if (leapInput > leapMax) //max
		leapMax = leapInput
//********


		leapNorm = (leapInput - leapMin) / (leapMax - leapMin) //perform normalization

	leapNorm * 12f //Multiply the normalized leap value by your scale

	myGameObject.transform.position.z = leapNorm;

Lerp and InverseLerp.

Vector3 gameObjPt1 = new Vector3(0, 0,  0);
Vector3 gameObjPt2 = new Vector3(0, 0, 12);
float   leapPt1    = -150;
float   leapPt2    =  150;

float   leapVal = <get the current value from leap>;

float   leapValNormalized = Mathf  .InverseLerp(leapPt1, leapPt2, leapVal);
Vector3 gameObjPos        = Vector3.Lerp       (gameObjPt1, gameObjPt2, leapValNormalized);