• 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 Feref2 · Mar 12, 2019 at 09:47 PM · scalethroughdecreasesubtractinggoing

Object´s scale is decreasing less than expected

So object B is moving, let´s say, 4 units to left. There is object A, which will be squeezed that exact distance. So if its scale is 10, - the 4 units will be = 6. As simple as that, but for some reason this isn´t working. Am subtracting the exact same distance object B is going through, but even though object A´s scale decreases, it decreses less than expected, like 3 instead of 4. That number is accumulating over frames.

I have verified several times that the number subtracted is indeed the correct number, and the script that makes this is executed after object B´s movement. Any ideas of what could this be?

Edit: I have discovered something. Instead of just subtracting the 4 units, am also subtracting the value of how much is going through, which I get using raycasts. Now, the interesting part is that, even though this number should be 0, is something like -0.002.. and is no longer accumulating, but it still becomes bigger and bigger (I think this is because the number is a percentage from the size reduction, which becomes bigger every frame). This is less noticeable than before. The raycast is thrown before the movement itself, so I think that am subtracting the extra value of the former frame. And the moving object is supposed to stop for a frame before going through. Why the moving distance isn´t enough?

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
0

Answer by Sibz9000 · Mar 12, 2019 at 10:02 PM

Scale is not number of units, it's a multiplication of size.

If your object, lets say cube for simplicity is 1x1x1, then a scale of 10 makes it 10x10x10 However if its 1.2x1.2x1.2, then a scale of 10 makes it 12x12x12.

So if we remove 4 from the scale of the first example, we get the expected size 6x6x6.

However in the second example we get 7.2x7.2x7.2 - not 8x8x8 as you may think.

If we have a smaller than 1 size, lets say 0.8x0.8x0.8 then the decrease would be less:

0.8x0.8x0.8 scaled by 10 = 8x8x8

Minus 4 from scale = 0.8x0.8x0.8 scaled by 6 = 4.8x4.8x4.8

The result is a size reduction of only 3.2, less than the 4 you would expect if thinking that scale is size.

Comment
Add comment · Show 5 · 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 Feref2 · Mar 12, 2019 at 11:41 PM 0
Share

Sorry, I forgot to mention that am doing this (transform.localScale.x * originalSize.x - moveUnit) / originalSize.x; That way I get the correct number and translate it into the transform Scale.

avatar image Sibz9000 Feref2 · Mar 13, 2019 at 08:41 AM 0
Share

Oh right, sometimes code really helps. If you can, post the important lines of what you are doing.

avatar image Feref2 Sibz9000 · Mar 13, 2019 at 07:42 PM 0
Share

float uScale = grounds[i].transform.localScale.x * groundScripts[i].originalScale.x; //groundScaleX[i] is first calculated. Is the final ground. groundScaleX[i] = (groundScaleX[i] - uScale) / 2;//Now changes to the half of how much is decresing or increasing from the current scale (am recycling variables to avoid garbage) for example (3 -5) / 2 = -1 is decreasing (the half is because the other object decreases the other half); Vector3 newScale = grounds[i].transform.localScale; newScale.x = (uScale + groundScaleX[i]) / groundScripts[i].originalScale.x; grounds[i].transform.localScale = newScale;

//the object that moves is connected to this ground (the floor´s reduction is what causes it to move). Logically speaking, it moves the groundScaleX[i] value.

Then there´s the other script which makes this:

currentX = transform.localScale.x * originalScale.x + leftRay.extra + allSizes.groundScaleX[leftGroundId]; //here am adding an extra ray from other script that measures how much is going through. This almost completely get rid of the issue, but that ray is thrown before.

//here´s the thing: even though the ray value should be 0 (if the object is perfectly colliding at the edge and isn´t going through) is something like -0.002..., but not constant. Subtracting this number really helps, but after some frames the issue appears again. I think this is because the ray shows how much ended up going through at the end of the previous frame. Throwing the ray after is complicated since I must calculate every position for the ray to be accurate, and after that, recalculate all grounds, which leads to recalculating this as well and is not good for performance, speacially because of how large the operation really is. Then the ray value from before - how much is decreasing should, logically, tell me this without needing to positionate everything beforehand. This was my original intention with the code line above, but again, for some reason the object needs to decrease more than the groundScaleX[i], which shouldn´t in the first place.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

101 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Decreasing object size until a certain size over time? 2 Answers

The REAL size of an object. 3 Answers

Dynamic Texture Tiling 1 Answer

Fixed distance between objects? 2 Answers

How to shorten/extend an object? 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