Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Paladin-Masayume · Jun 05, 2018 at 11:29 PM · cameraraycastscreenpointtoray

Cinemachine: ScreenPointToRay raycast

I'm trying to integrate Cinemachine into an existing project, and I hit a snag when trying to Raycast from a screen point. It seems to cast the ray from an orientation opposite to the starting orientation. It also never changes that orientation even if the camera rotates in both the scene and game view and renders properly.

    public RaycastHit findMouseOverPoint()
     {
         Ray ray = cam.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         Physics.SphereCast(ray, 0.5f, out hit, 1000.0f, pointerMask);
 
         mouseOverHit = hit;
         return hit;
     }
 
     void OnDrawGizmos()
     {
             Gizmos.color = Color.green;
             Gizmos.DrawSphere(mouseOverHit.point, 1);
     }
 

 
Comment
Add comment · Show 2
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 Paladin-Masayume · Jun 05, 2018 at 11:33 PM 0
Share

Interestingly, casting in OnDrawGizmos works properly in game view.

avatar image Tomer-Barkan · Nov 16, 2018 at 01:58 PM 0
Share

$$anonymous$$ake sure that you're running this script on the correct camera (that GetComponent returns the camera that you are refering to and not another one).

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by thieum · Nov 16, 2018 at 01:39 PM

I didn't tested your code, but note that CinemachineBrain (on your actual camera) has several update modes: LateUpdate, FixedUpdate, (smart?) Update. I solved a similar raycast issue (wrong camera.main position input) by having both CMBrain and my raycast function in the same pass (LateUpdate, for instance).

Hope it helps.

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 randyhuynh · Dec 01, 2020 at 07:00 AM 0
Share

I changed my camera to Fixed Update for both Update $$anonymous$$ethod and Blend Update $$anonymous$$ethod, however not my camera doesn't seem to be driven anymore. I can see the C$$anonymous$$ vcam1 moving, however, my main camera isn't following.

avatar image
0

Answer by Paladin-Masayume · Dec 01, 2018 at 08:24 PM

The problem in my case was another script that I use for the camera shake effect. Apparently, it changes the position of the camera in between frames sometimes and cinemachine takes that position. Sometimes the position is not off. Still might have something to do with those update rates you mentioned on the brain.

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

165 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

Related Questions

Why is the camera.screenpointtoray off? 1 Answer

Alternative to ScreenPointToRay needed 1 Answer

Follow mouse cursor (with Y = 0)? 1 Answer

Get 2D Collider with 3D Ray 2 Answers

Drag Camera only when raycasting Terrain 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