Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by aleem.razzaq09 · Jan 08, 2014 at 01:58 PM · spritescaleunity4.3

Grow Sprite image size from Edges instead of Center.

Hi, I am working on 2D game, in which I have multiples sprite Images and I want to increase the Height of Sprite Image on runtime and I can increase its size but its increasing from center so its also change its origin. I am doing like this "transform.localscale". Is this possible that I can just increase its height instead of increasing from center?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by robertbu · Jan 08, 2014 at 02:03 PM

If you select the texture you are using in your sprite, you sill see a 'Pivot' setting. Change this setting 'Center' to 'Bottom'.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aleem.razzaq09 · Jan 09, 2014 at 06:32 AM 0
Share

Thanks @robertbu, I changed Center to Bottom but getting same effect as getting on Center, I also changed to Bottom Right and Bottom Left these hold origin but it grow one side, I think I want Bottom as you suggest who can grow on both sided and hold its position, but I this not work. You can see in Inspector setting as attached image show. Should I need to do more?alt text

screen shot 2014-01-09 at 11.31.09 am.png (93.6 kB)
avatar image robertbu · Jan 09, 2014 at 08:30 AM 0
Share

I may be confused about how you have things structured. To make this work, the natural orientation of the spring needs to be vertical. That is, when the object has rotation (0,0,0), then the image needs to be vertical. How do you have your spring image oriented?

avatar image aleem.razzaq09 · Jan 09, 2014 at 10:43 AM 0
Share

Thanks @robertbu, and sorry for wrong orientation. First I don't need to place my spring vertically I need to show my both spring as attached image show. What I want when red ball move(using finger moving) then spring also streched or squeze according to movement with smooth movement and when user release red ball then it come back to its original position. Same Like as in this game "Ball Popper". This may be easy but I am new in unity so $$anonymous$$indly suggest me better approach to accomplish this task. alt text

avatar image aleem.razzaq09 · Jan 10, 2014 at 08:11 AM 0
Share

@robertbu, did u get my problem?

avatar image robertbu · Jan 10, 2014 at 02:26 PM 0
Share

The followup comment to what you want to do indicates that this problem involves a number of technical issues. Since UA question should focus on a single, specific issue, I'm going to answer the specific question you asked. The drag and drop, getting the spring to return to original position, calculating trajectory of the launched object, etc. are separate issues.

For what you are doing, I'd go back to placing the anchor in the middle of the sprite. You will need a separate sprite for each spring, and the image with rotation (0,0,0) must be vertical. Here is a bit of code that you can place on a spring to get it to scale between two positions:

 #pragma strict
 
 var goStart : Transform;
 var goEnd   : Transform;
 
 var factor : float = 1.0;
 
 function Start() {
     SetPos(goStart.position, goEnd.position);
 }
 
 function Update () {
     SetPos(goStart.position, goEnd.position);
 }
 
 function SetPos(start : Vector3, end : Vector3) {
     var dir = end - start;
     var mid = (dir) / 2.0 + start;
     transform.position = mid;
     transform.rotation = Quaternion.FromToRotation(Vector3.up, dir);
     transform.localScale.y = dir.magnitude * factor;
 }

This code goes on each spring. The SetPos() function takes two positions. You can derive these positions any way you want. In the rest of the script, I use two Transforms, but you could hard code a vector3 position for the anchor end of the spring. The 'factor' variable will depend on scaling factor of your sprite and may need to be adjusted based on your sprite's 'Pixels to Units' setting. I encourage you to explore this short script in a clean scene with two game object for start and end and a sprite. You can move the end points in the Inspector to test how it stretches the spring.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scaled sprite distorts on rotation in different resolutions 0 Answers

How expensive is scaling in 2D unity? Is it better to pre-scale? 1 Answer

How do I scale a 2D sprite over time? 2 Answers

Script to flip a sprite over the x axis not working? C#, Unity2D 1 Answer

How To Sync Scale in UNET 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges