# How to move an object's own Y position relative to a slider's Y position?

Essentially, I have a slider that you click and move along the Y axis between -4 and 0 positions. I also have an object that I want to move when you click and drag the slider, on the Y axis between -4 and 4 positions.

Can anyone tell me how to achieve this? I’ve tried multiplying/dividing the float variables and creating an offset but they don’t work. All I can achieve is the object moving alongside the slider’s y axis.

I want the object to move up and down the -4 and 4 Y coordinates relative to the slider’s -4 and 0 coordinates.

This is the code I’ve been tinkering with (forgive me if its messy but its the result of trying different things):

`````` Vector3 pos = transform.position;
pos.y = Mathf.Clamp(pos.y, -4f, 0f);
transform.position = pos;
/*units = (int)Mathf.Ceil(pos.y);
units = Mathf.Clamp(units, 0, 100);
pos.y = Mathf.RoundToInt(units);
print(units);*/

Vector3 pos2 = spaceship.transform.position;
pos2.y = Mathf.Clamp(pos.y, -4f, 4f);
spaceship.transform.position = pos2;
/*units2 = Mathf.Clamp(units2, 0, 100);
units2 = (int)Mathf.Ceil(pos2.y);
pos2.y = units2;
units2 = units;*/
pos2.y = pos.y;
``````

I’ve tried creating an Int that means 0-100 is the same as between -4 and 0 Y coordinates, in an effort to replicate the same result with the object’s -4 to 4 Y coordinates.
I’m obviously in a confusing position right now, as I’m probably trying code now that just isn’t going to work.
Can anyone figure out my issue?