• 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 RazorFinger · Jul 01, 2020 at 07:59 PM · rotationraycastnormalsflipped normals

Rotate an object from inside (With Flipped Normals)

I have a camera inside a sphere with flipped normals. When i click and drag, i'm supposed to rotate this sphere. Here is what i done:

     float rotSpeed = 20;
 
     private void OnMouseDrag() {
         float rotX = Input.GetAxis("Mouse X") * rotSpeed*Mathf.Deg2Rad;
 
         transform.RotateAround(Vector3.up, -rotX);
     }

Pretty simple code, and it works perfectly if the camera is outside the sphere. When inside tho, it doesn't work. I tried using raycasts, but they all can't hit the Sphere collider from inside. How do i do this? can't seem to find the answer anywhere

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Eno-Khaon · Jul 01, 2020 at 09:57 PM

One option would be to reverse the Raycast with the expectation that the sphere is what you would intend to hit:

 // If the current code is something like:
 Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);

 // ... you could invert it using something like:
 Ray invertedMouseRay = new Ray(mouseRay.origin + mouseRay.direction * sphereRadius * 1.01f, -mouseRay.direction);
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
0

Answer by LeFlop2001 · Jul 01, 2020 at 08:47 PM

Im not sure what youre probleme is but if its the collisiondection when castin rays from inside of colliders theres a checkbox under projectsettings/Physics called queries hit backfaces that solves that problem

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 RazorFinger · Jul 01, 2020 at 08:57 PM 0
Share

Weirdly enough it doesn't solve the problem, even with that i can't interact with the sphere from inside

avatar image
0

Answer by Bunny83 · Jul 02, 2020 at 10:18 AM

Well the OnMouseDrag callback is only called when Unity automatically detects a gameobject under the current mouse position. For this purpose Unity performs a raycast for you. Since you are located inside the object you can not hit the object.


Unless you really need that "when I click on that object" thing, I would suggest you just do:

 void Update()
 {
     if (Input.GetMouseButton(0))
     {
         float rotX = Input.GetAxis("Mouse X") * rotSpeed*Mathf.Deg2Rad;
         // rotate here
     }
 }

ps: Your RotateAround call doesn't look like it would work. You're missing the point you want to rotate around. See the documentation for RotateAround. When you just want to rotate around the worldspace up axis you could simply use Rotate with Space.World

 transform.Rotate(0, rotX, 0, Space.World);


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.

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

213 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

Related Questions

Rotating with a preferred driection. 0 Answers

Rotating to match surface normal makes object change its direction 1 Answer

Rotating an object to equal normals of object below 1 Answer

Using Raycast Normal to match surface rotation to instantiated gameobject? EXAMPLE GIF Included 0 Answers

hit.normal rotation problem, help please really confused 1 Answer


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