• 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 /
  • Help Room /
avatar image
0
Question by Ritches · Jun 28, 2016 at 09:37 PM · floats

Float calculation always outputting 0 when multiplied with another float....

The following is whats not working, basically every time I multiply the local position y of the object by any value other than an integer value declared in the shown script, it results in 0 and hence the object itself is moved to the origin , I've tried using doubles and all sorts of weird solutions , although to no avail , the y position of the object is currently really small at about -0.0195 , and i,m not sure if its just because the value is so small that when put into a calculation it's just read as 0 or not. If you are wondering the vertExtent is the orthograp$$anonymous$$c size of the camera in my scene and is set to 8 , so theoretically the value from t$$anonymous$$s should be 1 * ... but still doesn't seem to work.

 using UnityEngine;
 using System.Collections;
 
 public class ScaleLazerNodes : MonoBehaviour {
 
     // Use t$$anonymous$$s for initialization
     void Start () {
         gameObject.transform.localPosition = new Vector3(0, gameObject.transform.localPosition.y * (Spawner.vertExtent) / 8, 0);
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
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 btmedia14 · Jun 28, 2016 at 10:35 PM

The y position of -0.0195 is small and effectively, with x and z at zero, the object is close to the origin. Nevertheless, the calculation looks ok.

I assume Debug.Log for each stage of the calculation was used to display individual parts of the calculation. If so, note that Debug.Log defaults to rounding 1 decimal place, and so in t$$anonymous$$s example will always display y as 0.0. Suggest using a string formatter to display more decimal places:

 Debug.Log(gameObject.transform.localPosition.ToString("F4"));
 
Comment
Add comment · Show 2 · 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 Ritches · Jun 29, 2016 at 04:45 PM 0
Share
avatar image btmedia14 Ritches · Jun 29, 2016 at 09:46 PM 0
Share

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

59 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

Related Questions

the floats wont be applied, Random.Range 1 Answer

Floats not being added to other floats? 1 Answer

Min and Max value? 1 Answer

How round all floats with little script? 1 Answer

float to bool retardedness 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