Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Gillissie · Mar 09, 2011 at 07:20 PM · colliderraycastingbox

Raycasting question

I have a character that I want to track his eyes to where the mouse is pointing. To do this I set up a box collider and positioned it in the camera's view (see screenshot). I wrote a script for the collider to raycast from the mouse and point the eyes at the result. This works great.

However, the collider is preventing anything else from being raycast onto because it's blocking the whole scene. I have the character set up to do an animation if clicked, but it doesn't work while I have the collider box there.

Is there a way for me to only enable the collider box right before I raycast, then turn it off? I have tried setting hideFlags, but that didn't work. I also tried moving the collider box out of view, then temporarily back into view for the raycast, but that didn't work either.

Any ideas? Seems like this should be pretty straightforward.

Raycasting

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
1
Best Answer

Answer by DaveA · Mar 09, 2011 at 07:31 PM

Do you need to use a collider? I would suggest converting the mouse position to a world position, then have the eyes LookAt that point. If you need the collider, maybe putting it in a different layer would help.

Comment
Add comment · Show 5 · 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 Tuck · Mar 09, 2011 at 07:33 PM 0
Share

This is better than $$anonymous$$e. Do this.

avatar image Gillissie · Mar 09, 2011 at 07:53 PM 0
Share

I would prefer to do what you described, but I don't know how to convert mouse coords to world coords without using raycasting.

avatar image DaveA · Mar 09, 2011 at 07:58 PM 0
Share

http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenToWorldPoint.html and http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html

avatar image Gillissie · Mar 09, 2011 at 08:13 PM 0
Share

O$$anonymous$$G, that's exactly what I needed. I'm so new to Unity that I'm still learning the native functions. Thanks!

avatar image DaveA · Mar 09, 2011 at 09:19 PM 1
Share

No problem. I find the documentation is quite excellent, many times the exact bit of code I need is already there as an example. And it's google-able!

avatar image
0

Answer by Tuck · Mar 09, 2011 at 07:32 PM

There is a layer called ignoreRaycasts or something you could use. At the start of a frame, set the collider's layer to a raycast-able layer, track the eyes to the mouse, then set the collider layer back to ignoreRaycasts.

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

No one has followed this question yet.

Related Questions

Internal collisions 1 Answer

3D text with box collider Android 1 Answer

Paddle which control by Cpu for Air hockey game 0 Answers

Is it possible to skew a box collider? 1 Answer

how to resize box collider? 4 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