Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 dalessan9 · Aug 19, 2018 at 02:44 PM · mathconfusedincorrect

Unity not giving correct solution to equation

I'm attempting to make a shmup wave spawner object that can spawn enemies in set patterns -- currently working on the "greater than" shape: > I came up with a formula that works in google sheets - the basic calculator that comes w/ windows - and everywhere else -- Unity, however, decides to give the wrong answer. The image attached - shows my google sheet - where I came up w/ the equation and tested a few values. On the right side, I simplify things and just Debug.Log the equation w/ preset values... and show the console result.

what should be 3.4, 2.3, 1.1 - is somehow 4, 4, 4

What gives?

alt text

untitled.png (51.0 kB)
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 eses · Aug 19, 2018 at 04:40 PM 0
Share

Hi @dalessan9 - Try adding "f" after your numbers. Currently your numbers will be int numbers ins$$anonymous$$d of float number. So change 4 to 4f and so on. Otherwise you'll divide 4 by 7 and result will be whole numbers. I added this as answer + an example.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by eses · Aug 19, 2018 at 04:43 PM

Hi @dalessan9

Try adding "f" after your numbers.

Currently your numbers will be int numbers instead of float number.
So change 4 to 4f and so on.

Otherwise you'll divide 4 by 7 and result will be whole numbers, see example below:

 Debug.Log("Calc ints:" + 4 / 7); 
 
 // Calc ints:0
 
 Debug.Log("Calc floats:" + 4f / 7f); 
 
 // Calc floats:0.5714286

Comment
Add comment · Show 3 · 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 dalessan9 · Aug 20, 2018 at 04:22 AM 0
Share

kind of infuriating to have to specify that w/ generic numbers used in a formula - I'd call it a bug - but that's probably built in to C#

another one of those - assume it's stupid - and you're probably right - type of things thanks

avatar image Bunny83 dalessan9 · Aug 20, 2018 at 07:31 AM 0
Share

No this is not a bug or anything weird. It's just your lack of understanding the program$$anonymous$$g language. Integer divisions existed in most CPUs before we got floating point numbers support.


Try switching your windows calculator into programmer mode and you actually get integer divisions as well. You should learn about datatypes.


btw:

this would only make any sense if you were expecting integer division as this would round down to the closest multiple of 7. Though in your case always to 0

 (((0 + 1) / 7) * 7)

However if you expect this to perform a floating point division it just makes no sense as it's the same as just

 (0 + 1)

So even the formula in your sheet makes no sense as you divide and multiply by the same value which has no effect.

avatar image dalessan9 Bunny83 · Aug 21, 2018 at 12:45 AM 0
Share

sorry, I know you tried pretty hard, but I need more rep to down vote your comment

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

95 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

Related Questions

Any Good References for Game Math 1 Answer

Implement the equation as a code? 1 Answer

Random.seed Repeating 2 Answers

Normal distribution random 3 Answers

Detect where line intersects outline shape 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