Scale from one side?

Hi,

When I scale an object, it changes it’s size according to both it’s sizes. Is it possible to scale an object in a way that one side of it doesn’t move?

For example, imagine that you have a cube that represents one floor and you want to change it’s scale so it would represent two floors (I know I can instantiate another cube on it, but I don’t want to).

When I change a cube that represents a floor, the way Unity does it is that it adds a little to top of the cube and little to under it but I want it to just make the cube bigger by extending it’s height, i.e. do not reposition the bottom of it.

Thanks.

1 Like

There are a couple of ways to approach this problem. The first is to do as @Quillicit suggests and move the position as you resize. In my Answer here I extend a box on one side using that technique:

http://answers.unity3d.com/questions/473076/scaling-in-the-forward-direction.html

The second solution is to move the pivot point of the object to the side you want to use as your base for extension. This is best done in a 3D modeling program. You can do it with meshes in Unity, but you would have to jump through some hoops to do it for built-in objects such as Cubes. The issue is that you could be modifying the underlying Unity cube, not just a cube you want for this particular purpose. Here is an editor script for moving the pivot point:

http://wiki.unity3d.com/index.php?title=SetPivot

And @HappyMoo’s empty game object solution will work for built-in objects. Thumbs up for him…I’d forgotten that.

  • Place an empty game object on the side of the object that is to be the base
  • Make the visible object a child of the empty game object
  • Scale the empty game object.

There are more than one possibility to solve this.

One would be to get something from the AssetStore to change the pivot point - there should be something free.

(EDIT: This is not recommended for built-in primitives like cubes, because you might end up changing them permanently.)

Or you create an empty GO and place your cube accordingly inside it and then scale the parent GO instead of the cube.

Found this question, to help others who may stumble to this problem, just a simple solution.

Use the Rect tool on 3D objects, it moves the pivot along with an edge so you will get the solution by simple dragging on a side.

I know this is very late but for any other latecomers:

As long as you have a source image in the image component you can change the image type to filled, then choose for example horizontal and left which will fill from left to right when you change the fillAmount.

You can change the fillAmount in script by accessing it with ex. “Object”.GetComponent().fillAmount;

I just spent two hours trying to do this, and finally found it!

So I got you guys on this one. Just found a super easy solution on how to do this. I am going to be using a simple cube as what I’m scaling, for example.

  1. Create the cube.
  2. Create an empty GameObject
  3. Move the empty GameObject to the bottom of the cube, (Underside if in 3D scene). Make sure it’s at the exact bottom.
  4. Now, make the empty GameObject the parent of the cube. (Drag the cube onto the empty GameObject).
  5. Next, add your scaling script to the EMPTY GAMEOBJECT. Make sure you DO NOT add/keep the script on the CUBE.

Note: Just in case you’re confused on how to scale the object, use:

transform.localScale = new Vector3(x, y, z); OR
transform.localScale += new Vector3(x, y, z);

Just make sure to use localScale instead of something else

Thanks for reading! Hopefully you found this useful! Reply if you have any problems. Remember to @ me!

Just use Rect Tool