Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 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 this 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 anything, 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 hitInfo;
             if (Physics.Raycast(ObjectRay, out hitInfo))
             {
                 Mimic.transform.position = hitInfo.point;
                 Mimic.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
             }
         }
     }

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

Comment
Add comment · 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
0
Best Answer

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

I figured the problem, nothing 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
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

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

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

Raycasting is hitting objects and not hitting them at the same time 1 Answer

Creating A Seesaw Lever 0 Answers

"SetDestination" can only be called on an active agent that has been placed on a NavMesh 1 Answer

How do I change the pivot points on each poly of this icosphere? 2 Answers

Selecting and deselecting gameobject to change material 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