Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Astrydax · Jul 04, 2021 at 12:37 PM · rotationscripting problemvector3gimbal-lockvalidation

locations being stored in map manager are inaccurate and ruining overlap validation.

https://youtu.be/uKblVWHaqn0

I don't understand why sometimes the sections are deactivating like they should... and sometimes they are not. All I'm trying to do is make sure the maze pieces can't be placed on top of each other (unless I want them too... users will get a power up where their tiles "crush" underlying tiles, so I have to be mindful of that feature now.

MazeManger.cs

   public static void SectionPlaced(GameObject mazeTile)
     {
         SectionValidation[] children;
         children = mazeTile.GetComponentsInChildren<SectionValidation>();
         foreach (SectionValidation sectionValidation in children)
         {
             
             if (instance.placedSections.Contains(sectionValidation.gameObject.transform.position))
             {
                 Debug.LogError("placed two sections in same spot");
             }
             else
             {                
                 instance.placedSections.Add(sectionValidation.gameObject.transform.position);
             }
         }
         EventManager.TriggerEvent("OnPlaceTile");
     }
 }

BuildController.cs

   private void RotateGhost()
     {
         ghost.transform.Rotate(Vector3.up * 90.0f);
         currentRoty += 90.0f;
         if (currentRoty >= 360) currentRoty = 0.0f;
         
         SectionValidation[] children;
         children = ghost.GetComponentsInChildren<SectionValidation>(true);
         foreach (SectionValidation section in children)
         {
             section.gameObject.SetActive(true);
         }
         EventManager.TriggerEvent("OnMoveGhost");
     }
 
     private void PlaceMazeTile()
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out RaycastHit hitInfo, 300f, mask))
         {
             if (!equippedTile) return;
             targetNode = hitInfo.transform.gameObject;
 
             GameObject placed = Instantiate(ghost, new Vector3(targetNode.transform.position.x, 0, targetNode.transform.position.z), Quaternion.Euler(0, currentRoty, 0));
             
             MazeManager.SectionPlaced(placed);
 
             if (ghost) Destroy(ghost);
         }
     }
 
     public void MoveGhost()
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out RaycastHit hitInfo, 300f, mask))
         {
             if (!equippedTile) return;
             //only run the first time we hit a new node
             if (hitInfo.transform.gameObject == targetNode) return;
             targetNode = hitInfo.transform.gameObject;
 
             if (ghost) Destroy(ghost);
             ghost = Instantiate(equippedTile, new Vector3(hitInfo.transform.position.x, 0, hitInfo.transform.position.z), Quaternion.Euler(0, currentRoty, 0));
             EventManager.TriggerEvent("OnMoveGhost");
                      
         }
 
     }

SectionValidation.cs This is placed on every 1x1 square section of the tile... like minos making up a tetromino

  private void OnMoveGhost()
     {
         if (!isGhost) return;
 
         if(MazeManager.instance.placedSections.Contains(this.gameObject.transform.position))
         {
             this.gameObject.SetActive(false);
         }
     }





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

2 Replies

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

Answer by tyruji · Jul 05, 2021 at 11:19 PM

In your SectonValidation script, you could make a Vector3Int property, and use that instead of transform.position, this way you won't suffer from floating-point inaccuracy.

Comment
Add comment · 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
1

Answer by melkior · Jul 05, 2021 at 04:42 PM

@Astrydax you are almost certainly dealing with floating point precision errors. This is a well documented problem in computing and is not limited to Unity. Doing some google searches on it will show you many people experiencing this issue.

A quick search found this on Unity forums which has an answer from a user called lordofduct that you should probably review.

If you refactor your code to add integers instead of floats, and then cast them to floats it might solve or reduce your issue

So change this bit:

  ghost.transform.Rotate(Vector3.up * 90.0f);
          currentRoty += 90.0f;
          if (currentRoty >= 360) currentRoty = 0.0f;


To something like this:

      ghost.transform.Rotate(Vector3.up * 90);
         currentRoty += 90;
         if (currentRoty >= 360) currentRoty = 0;


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 Astrydax · Jul 05, 2021 at 10:52 PM 0
Share

that line was originally that. I changed it to a float to see if it made a difference.

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

264 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 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 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

Sprite Rotation Messed up,Rotation is choppy and messed up 0 Answers

Why does this code not work? 1 Answer

Get Y Rotation Between Two Vector3 Points 2 Answers

Calculating Scrolling GameObject x position scrolling pass another GameObject x postion (2D Game) 1 Answer

Quaternion.Euler rotations don't add up 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