# How do I elongate (non-uniformly scale) and rotate a cube simultaneously?

Hi there,

What I’m trying to do:

I have a cube spawned in the world, and based on how the player moves his mouse around, the cube needs to both rotate and elongate in only one direction. This gives the player the ability to create “logs”, if you will, of any length at any rotation. Additionally, the cube must be parented to an empty game object that resides on the back face (negative Z) of the cube, so that it may scale in one direction, not forwards and backwards.

The problem:

Rotating the cube while also scaling it in one direction (along the Z, because the cube is being rotated to face the point in the world which the player hits with their touch’s raycast) causes the cube to skew heavily. The scale also pops oddly while rotating. The rotation is applied to the child (original) object, so that it does not rotate around the offset empty parent object.

Considerations:

I’ve read up on problems that Unity has with rotating children of non-uniformly scaled parents. What I need to know is if there is a work-around that will do for my particular set up, or if something else is required. I’m considering a solution where I grab the four verts farthest on the Z (representing the “front face”) and just move their Z coordinate. Not sure if I will have the same problem.

Thank you!

EDIT: I also came to a realization - the scaling issue is caused by the existence of an empty game object parent that I’m using to get the cube to scale in only one direction. If there was a way to elongate the cube in only one direction without the empty parent, that would also (theoretically) solve my problem. Again, perhaps the vertex moving solution will work, but I’d appreciate any feedback or potential pitfalls.

A friend helped figure it out. The solution was to use three game objects, in this way:

• Rotation Center (Empty Game Object)
- Scale Center (Empty Game Object)
- Actual Game Object (Cube)

The rotation center was at 0,0,0. Relative to it, the scale center was at 0,0,-0.5, allowing the prefab to scale along the Z in one direction. The actual object was then at 0,0,0.5, effectively putting it back at the rotation center’s location.

Of course, now neither rotation or scale is directly applied to the actual object. Rotation is applied to the rotation center object, and scale is applied to the scale center object. Parenting takes care of the rest.