• 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
Question by braydonvogel · Jun 13, 2021 at 02:48 PM · error3draycastingpivot-point

Raycast hitInfo position placement not relative to Pivot Point.

So I'm making a script where you can hold "F" to make a transparent object appear where you are pointing on a 3D plane (Using a Raycast), and then when you press MB1 it'll place your object in hand where that transparent object is.

Now, I managed to make most of that work, except that when it goes to position the Cube it always has half of the cube in the ground. I've figured that t$$anonymous$$s was it's attempt to connect the Cubes Pivot Point to the Raycast position, and when I've changed the pivot point in blender to the cubes bottom-face It hadn't fixed anyt$$anonymous$$ng, It was still centre in the ground.

Mimic is the name of the transparent object. Item is the name of the object being held

Here's the code:

 if (equipped)
     {
         placing = true;
         if (!isMimic)
         {
             isMimic = true;
             Mimic = GameObject.Instantiate(Item);
             Mimic.name = "PlacementMimic";
             Mimic.GetComponent<Renderer>().material = mimicMaterial;
             Destroy(Mimic.GetComponent<Collider>());
         }
         if (Mimic)
         {
             Mimic.transform.localScale = Scale;
             Ray ObjectRay = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit $$anonymous$$tInfo;
             if (Physics.Raycast(ObjectRay, out $$anonymous$$tInfo))
             {
                 Mimic.transform.position = $$anonymous$$tInfo.point;
                 Mimic.transform.rotation = Quaternion.FromToRotation(Vector3.up, $$anonymous$$tInfo.normal);
             }
         }
     }

I'm still fairly newbie in Unity, so if it's some obvious error please go easy on me. Thanks in advance.

Comment

People who like this

0 Show 3
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 unity_HTr7mOeTIRzvVA · Jun 13, 2021 at 03:24 PM 0
Share

Did you check if you're using the cube from blender? Or apply the overrides item prefab?

Or Try pivoting it with empty, kind of "snap points" from the other games which where you can add more than one.

avatar image braydonvogel unity_HTr7mOeTIRzvVA · Jun 14, 2021 at 02:09 AM 0
Share

I'm so sorry! I figured out the answer just now, It was the rotation that was wrong, I had to go in blender and rotate it 90 degrees and change it's pivot point again, because I realized unity had automatically added 90 degrees to it's X axis, Thank you though for your help.

avatar image unity_HTr7mOeTIRzvVA · Jun 14, 2021 at 04:50 AM 0
Share

Oh! Yeah that's because the axis of blender is different from other 3d softwares

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by braydonvogel · Jun 14, 2021 at 02:10 AM

I figured the problem, not$$anonymous$$ng to do with the script or the pivot point, it's just that unity automatically changed the X axis by 90 degrees, simply changing the axis and resetting the pivot point to the bottom in blender fixed it flawlessly.

Comment

People who like this

0 Show 0 · 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

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

195 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

Related Questions

Raycast hits and affects all items within the same tag 2 Answers

Detecting the location of a shadow that is being projected onto a plane 1 Answer

Error in Code 1 Answer

BCE0004: Ambiguous reference 'Quest': Quest, Quest. 0 Answers

Spherecast. Want to determine how close to the center of the sphere the collision occurred. 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