- Home /
Stretch sprite one direction
Hello, I'm having a lot of difficulties stretching a gameobject in one direction only. My understanding so far based off of this post: http://answers.unity3d.com/questions/583187/how-to-make-sprite-renderer-increase-in-size-on-on.html
SO, if an object's position.x is increased by 1, then we would need to scale the object by .5 in order for it to remain in the same position and appear to increase on one side.. when I try, however, there is a small offset and the opposite side is slightly shifted each frame.
Example code I've been messing around with (called each frame):
Vector3 tonguePosition = _tongues [0].transform.localPosition;
tonguePosition.x += 0.05f;
_tongues [0].transform.localPosition = tonguePosition;
Vector3 tongueScale = _tongues [0].transform.localScale;
tongueScale.x += 0.025f;
_tongues [0].transform.localScale = tongueScale;
Every frame this extends the "tongue" on the right but it's left is also being stretched a small amount each time. I can't understand where this offset is coming from... help please?
Answer by yashpal · Dec 02, 2014 at 01:37 PM
@nissassAlivE , if you wan to scale your object by 2 than your game object position is increase by 1
Vector3 tongueScale = transform.localScale;
tongueScale.x += 0.08f;
transform.localScale = tongueScale;
Vector3 tonguePosition = transform.position;
tonguePosition.x += 0.04f;
transform.localPosition = tonguePosition;
OR you can change your sprite import setting change pivot to "Top Left"(or custom to make center left) to increase bar in right side. and just increase scale. Don't change position;
Vector3 tongueScale = transform.localScale;
tongueScale.x += 0.08f;
transform.localScale = tongueScale;
Your answer
Follow this Question
Related Questions
Will humanoid rigs ever support stretch? 0 Answers
Stretching a gameobject to fit viewport 4 Answers
Prevent the screen from stretching in different resolutions 0 Answers
How to stretch a scale 0 Answers
How to modify scale of sprite 1 Answer