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
0
Question by nishantjani · Mar 04, 2015 at 12:00 PM · c#unity 2dscalingunity 4

Scale fishing rod in one direction

Hello all,

This may seem like a repeated question, but I have tried all the code possible to achieve what I'm trying. I have a fishing rod and a hook at the end of the rod. Where ever I click on the screen, based on the y index of the click I move my hook to that position. So say for instance my hook is currently at (2,3) if I click at (400, 9) I move my hook to (2,9). So i just move it vertically based on the click.

This is working fine. Now based on the position of the hook I want to scale my fishing rod accordingly. So once im done positioning my hook I call the following ScaleRod(). The rod sprite has a pivot at top-left, and not center. I want to rod to scale only vertically. Below is my code for the same:

     void scaleRod() {
         //get current size of the fishing rod
         var rodLength = System.Math.Abs(renderer.bounds.size.y); 
         //Get distance between the hook and the rod based on y coordinates.
         float hookRodDistance = (System.Math.Abs(transform.position.y) + rodLength) - System.Math.Abs(hookObject.transform.position.y);
         hookRodDistance =  System.Math.Abs(hookRodDistance);
         //Calculate the scale factor
         float scaleFactor = hookRodDistance / rodLength;
         //Scale  the rod        
         transform.localScale = new Vector3(transform.localScale.x, scaleFactor * transform.localScale.y, transform.localScale.z );
     }


The function is giving me wierd output on the scale.

Can someone please help. Have been stuck for a while on this. Thank you so much.

Comment
Add comment · Show 1
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 Owen-Reynolds · Mar 04, 2015 at 03:00 PM 0
Share

Is the rod a child of something? Is it rotated? Sounds like a childed non-uniform scale problem.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by curiouspers · Mar 04, 2015 at 03:27 PM

Change this line:

 float hookRodDistance = (System.Math.Abs(transform.position.y) + rodLength) - System.Math.Abs(hookObject.transform.position.y);

to this:

 float hookRodDistance = hookObject.transform.position.y - transform.position.y;

And it should work. And i'm not sure why you want to use Math.Abs, maybe you need to remove it.

Comment
Add comment · 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
0

Answer by Tuncer · Mar 04, 2015 at 01:52 PM

This is actually about pivot point of your object. In Unity3d, pivot points can not be changed. However, there is really an easy solution :

You can use empty parent GameObject and child is gonna be your fishing rod. Move your empty parent GameObject to edge of your fishing rod which is opposite side of direction which you want to scale and now, you can scale easily parent GameObject to scale your fishing rod in one direction.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Scaling unity apps 1 Answer

Name not saving to or loading from PlayerPrefs 1 Answer

Only the first half of my coroutine works 1 Answer


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