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 Nerethar · Aug 07, 2013 at 02:58 PM · c#ipadapple

C# Code working on PC won't work on Mac's

Hey guys, I got a strange problem with my code.

I tried to move an object and after it reached its destination, I want to move it into a defined position (in my example, -100 for all 3 coordinates).

It works fine on the PC, but won't work correct on Apple Products (Mac, iPad etc...).

My Code looks like

 ...
     while( MyObject.transform.position != targetDestination){
                 t += Time.deltaTime / duration; 
                 MyObject.transform.position = Vector3.Lerp(MyObject.transform.position, targetDestination, t);
                 yield return 0; // suspend execution till next frame            
             }
             print ("after the while");
             MyObject.transform.position = new Vector3(-100f, -100f, -100f);
             
             yield return new WaitForSeconds(0.2f);    



Like I said, on PCs, this works excellent, on Macs, it won't. On Apple products it seems to end after the while{} since the "after the while" won't appear on the consol. This lines are executed in a coroutine.

Does anybody know why whats the problem here?

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
1
Best Answer

Answer by Xtro · Aug 07, 2013 at 03:11 PM

OMG :) You can't test if the position equals to destination. It never will be the same value. In 3D world, we are dealing with float numbers and they are not real mathematical floats.

Destination check is more complex that just checking against the equality of the coordinates. Even if it works on PC, it's based on luck and you should never trust it.

Easiest way to make a destination check is the distance measurement. Get the distance between the positions. If it's smaller than a predefined distance limit, you can say it reached the destination.

don't forget that distance measurement will fail if the object moves too fast. Because it can skip the detection area in one game update loop.

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 Nerethar · Aug 07, 2013 at 04:03 PM 0
Share

Thanks dude, that was excactly the solution. But on the other hand, I think its kinda strange that it worked every time on the PC and never on the $$anonymous$$ac, since it aparently allways rounded wrong o_O'

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

15 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Ios Tap Function 1 Answer

moving to iOS- XML files 2 Answers

could players to play music from itunes in my app? 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