- Home /
¿Is it possible to scale independently of the rotation?
Hello,
I'm trying to build some kind of scaling of a Cube through a UI interaction. In this UI I have four handlers arranged on a square: top, bottom, left and right.
I'm currently scaling the object correctly detecting how much the handler has moved from the position of the first click and apply that distance to the scale of the Cube (differenceInX/Y), so if I move the right handle to the left/right, the object is scaling on the X-axis and if I move the handler on the top/bottom the object is scaling on the Y- axis. I'm doing this using localScale this way:
mCube.transform.localScale = new Vector3(localScale.x + differenceInX, localScale.y, localScale.z);
My problem starts when I apply a rotation to the Cube, because I want to still resize my Cube to the right if I move the right handler, but, for example, if my Cube is rotated 90º on Z axis, the axis at the right side of the Cube is -Y, not X anymore. This also applies to a rotation in Y, for example, with a rotation of 90º in Y the axis at the right side is -Z.
So I thought of changing the resize axis depending on the range of rotation the object has, but because rotations can be applied freely, I don't know how to control ranges of accumulated rotations in multiple axes. I think I may be missing something that can make this easy.
I ask if someone knows how can I scale an object always to its top/bottom/left/right side without taking care of the rotation. If a Cube is rotated in multiple ways, if I move the right handle I want to scale its right side from my point of view.
Thank you very much and I hope I explained it well.
do everything locally. my suspicion is that you are not transfor$$anonymous$$g the mouse coordinates into the cubes space. use cube.transform.InverseTransformPoint(mouse.position) (pseudocode) to get the mouse in its local space, do all your calculations there
It works!! I needed just to know that, now I can finally detect where to move my Cube. Thank you very much!
Your answer
Follow this Question
Related Questions
how to only get the negative or positive part of a GetAxis 1 Answer
Rotate cube in two direction not working 1 Answer
How to lock a transform's local up axis rotation on any surface 1 Answer
How to leave bevels of an object (created in Blender) as they was created? 1 Answer
LookAt() with X axis 1 Answer