- Home /
How can I scale my object "upwards"?
I am using localScale.y to scale a cube but I would like the scaling to make the cube "taller" rather than the current way which ends up with half of it through the floor This is most easily explained with a picture. (1) is the original cube. (2) is what I want. (3) is what I get.
Now I do understand why this happens. The cube is scaled from the center point in both directions equally.
My app is a music visualisation program so the scaling happens a few times per second so I don't think it is poissible to keep on correcting the y position of the cube else the cube will be out of place when the cube gets smaller.
Is there a nice way to change how the cube is scaled or a workaround for this?
Answer by DaveA · May 22, 2011 at 02:46 PM
Actually, yes, you can change the y position, it updates very quickly, should be just fine. But if that is really not what you want to do for some reason, a) model the cube with Blender or other 3d program, where the origin is at the bottom, or b) put the cube into an empty gameobject, offsetting it upward .5, so the new gameobject, when at 0,0,0, has a cube in it that sits 'on the ground', then scale that containing object instead.
I think I'll go for option B. The scaling is happening according to my spectrum data so it's tricky to tell how much I should move it on the Y axis each time (unless there is a way to get the translation directly based off the scale?)
Of course there is, GesterX. With a y-scale of 1 the origin is at 0.5 and the 'floor' is at 0. If the y-scale is 2 the origin is at 1, Etc.
So every time you scale simply put the y position at the y-scale*0.5
Answer by Zhapness · May 22, 2011 at 03:22 PM
You should just do:
transform.position.y = 0 + transform.localScale.y/2
that way the object will start at point 0 no matter its size.
Answer by Abdullah Sattar · Sep 25, 2013 at 12:23 PM
Hello. The above mentioned technique is also a solution but if you have any designer or any know how to use 3ds Max or Maya you can set the pivot point of that object to the bottom which you mentioned earlier (Cube), and just scale it upwards then see it will only scale in the upward direction and the bottom positioning will remain un-effected. Set Pivot point to the bottom of the cube or opposite to the side in which you want to scale which is bottom.
Your answer
Follow this Question
Related Questions
scale gameobject with particle system as child 0 Answers
How to make an object's localscale values grow and shrink within a few seconds? 0 Answers
problem Changing Scales in Script -C# 4 Answers
Object's localScale 1 Answer
Rescaling goes wrong? 0 Answers