- Home /
How to change image height without changing in x y.
Hi, I am working on 2D game in Unity 4.3. I have a spring Image, which I want to change its height on finger swipe, I can change via using "transform.localscale" of that Image but whats happening its position also change on size changing. I want to stick its position but just to grow and decrease image size on Swipe. I also attached image whats happening on left spring, its size but it also goes up of white line, this I don't want to do. Kindly suggest me some better approach to accomplish this task. Thanks in advance.
Is this a dup of your other question or is something more going on here:
Answer by yatagarasu · Jan 09, 2014 at 01:09 PM
No it's position is not changed when you scale it. What changes is position of both ends relative to it's position. And in sprites objects position corresponds to sprite pivot point.
So what you need to do is set sprite pivot point to start of your spring (left or right if your spring sprite is horizontal or to top and bottom if it is vertical). And than scaling will keep it's beginning stationary and will move only other end.
Thanks @yatagarasu, I am doing like but It really required lot of calculation to follow finger position, because for this I need to change angle and its size as well this is bit tricky. So I think you are experienced in Unity, so is this possible that Unity has some default feature for this or is there any other quick approach for this to accomplish this task. kindly share with your experience bcoz I am new bee in Unity3D.
Unity have a builtin 2D physics engine which can solve your task, but i have never used it.
If you want to calculate scale and rotation by hand. You should calculate a vector between ball and spring fixed joint (attached to the ground). The length of this vector will be scale
times greater than the length of the spring. The rotation can be found with a Quaternion.RotateTowards