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 /
  • Help Room /
This question was closed Jul 16, 2017 at 04:49 AM by Walter_Hulsebos for the following reason:

Duplicate Question

avatar image
0
Question by Walter_Hulsebos · Oct 15, 2016 at 06:21 PM · float

My calculation won't give me floats.

 using UnityEngine;
 
 public class AiRaycast : MonoBehaviour
 {
     public GameObject player;
     public int SpotRayCount = 12, SpotRayLenght = 10, SpotAngle = 90;
     void Update ()
     {
         float rot = -((SpotAngle/ SpotRayCount) * (SpotRayCount/2));
         print((SpotAngle / SpotRayCount));
         print((SpotRayCount / 2));
         for (int i = 1; i <= SpotRayCount; i++)
         {
             print(rot);
             Debug.DrawRay(transform.position, Quaternion.AngleAxis(rot, transform.up) * transform.right * SpotRayLenght, Color.blue);
             rot += (SpotAngle / SpotRayCount);
         }
     }
 }
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 Walter_Hulsebos · Oct 15, 2016 at 06:15 PM 0
Share

90/12 should equal 7.5 but it prints 7, why is this?

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by doublemax · Oct 15, 2016 at 06:29 PM

If there are only integers on the right side of the equal sign, the compiler will perform a division of integers.

You need to cast at least one INT to FLOAT to get a float divison.

 float f = (float)SpotAngle / SpotRayCount;
Comment
Add comment · Show 1 · 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 Walter_Hulsebos · Oct 15, 2016 at 06:46 PM 1
Share

Thanks, I did not know that yet

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

transform.position inconsistent numbers problem 1 Answer

Analytics - Funnel parameter (float) is always 0 1 Answer

How do I convert speed and heading to a vector? 3 Answers

Why doesnt the value change? 2 Answers

Trying to get doors to close after x time since the player has passed through the previous? 0 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