Keep the distance of one object relative to another while changing its size
Hello to anyone who reads. I would like to ask for help / advice. I am working with the VRTK plugin, I created a scene in which with a slider I can increase the size of an object, between two parameters (min and max). This object is at a certain height with respect to the floor, however very close and it is an interactive object, with VR I can pick it up and position it somewhere else. The moment I increase the size of the object, a part of this object enters the floor, which is what I'm trying to fix. In the code I wrote, I take as a reference the point where the object is instanced (I created a locator in the scene) and with a vector3.learp I can do what I want, with the increase of the size also increases its position in the Y axis and therefore does not go inside the floor, but here the problem arises, if by chance I take the object, I move it to another area, and then I try again to increase its size, the object returns to the place where the instancing takes place ... can you help me?
This is the code:
This part of the code works, but the problem described above occurs because of the locator.
 protected virtual void ValueChanged(object sender, ControllableEventArgs e)
             {
                 if(cube_1 != null)
                 {         
                     //This is for change the size
                     cube_1.transform.localScale = e.value * (Vector3.one / 100f);
     
                     //This is for change the position 
                     Vector3 posInit = new Vector3(0, positionOfSpawn.position.y, 0);
                     Vector3 pofFin = new Vector3(0, positionOfSpawn.position.y + 0.1f, 0);
                     cube_1.transform.position = Vector3.Lerp(posInit, pofFin, e.normalizedValue);
                 }
                 else
                 {
                     return;
                 }
             }
            
 
               This code doesn't work, I wrote it because I thought, instead of taking the instance point as a reference, take the point where the object is
 protected virtual void ValueChanged(object sender, ControllableEventArgs e)
         {
             if(cube_1 != null)
             {
                 //This is for change the size
                 cube_1.transform.localScale = e.value * (Vector3.one / 100f);
 
                 //This is for change the position 
                 Vector3 posInit = new Vector3(0, cube_1.transform.localPosition.y,0);
                 Vector3 pofFin = new Vector3(0, cube_1.transform.localPosition.y + 0.1f, 0);
                 cube_1.transform.localPosition = Vector3.Lerp(posInit, pofFin, e.normalizedValue);
             }
             else
             {
                 return;
             }
         }
 
               I thank anyone who can help me. Regards Cristian
Your answer
 
             Follow this Question
Related Questions
Hey Guys How to make a script 'private Transform Waypoint;, 0 Answers
Character Spin Issue 1 Answer
Is there a way to make OVR tracking space follow player rotation? 1 Answer
Disabling unity premade script component,Disabling sealed public script component 1 Answer
Object reference not set to an instance of an object [problem with Unity 5] 2 Answers