Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 zerophase · Jun 22, 2014 at 04:36 PM · 3dvolumegeometryvector math

Check if GameObject is within the volume of a cone.

Currently, I'm making an adventure game similar to Myst. The only issue I'm having is the raycast used to tell if the player is looking at a switch or button is too precise to feel good without a reticle. To solve this I'm moving towards testing if a point on an object is between 4 points on a cone.

I've got the 4 points moving about the enviroment based on the direction the player is facing, and the only thing I'm not that sure on is the math for this test. Should I take the cross product between 2 points and if those 2 satisfy the condition check the next two? Maybe a pyramid is a better shape to use.

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

Answer by meat5000 · Jun 22, 2014 at 04:44 PM

My answer disappeared! :D

Anyway, I'll write again.

Try SphereCast

Its a fat Raycast

Comment
Add comment · Show 2 · 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 zerophase · Jun 22, 2014 at 04:40 PM 0
Share

Oh wow, that would be even easier. I don't need all of my currently active buttons to register with the script responsible for notifying them on an intersection. Thanks.

avatar image Westland · Feb 02, 2019 at 03:12 PM 0
Share

Hahahahahahahah, fat raycast

avatar image
1

Answer by Tortuap · Jan 15, 2021 at 10:09 AM

For anyone looking for a is point inside cone test routine :

 public static bool IsPointInsideCone ( Vector3 point, Vector3 coneOrigin, Vector3 coneDirection, int maxAngle, int maxDistance )
 {
     var distanceToConeOrigin = ( point - coneOrigin ).magnitude;
     if ( distanceToConeOrigin < maxDistance )
     {
         var pointDirection = point - coneOrigin;
         var angle = Vector3.Angle ( coneDirection, pointDirection );
         if ( angle < maxAngle )
             return true;
     }
     return false;
 }
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 robertbu · Jun 22, 2014 at 04:49 PM

The typical solution to the problem is to put a collider on object like switches and raycast against colliders on these objects. When the player's raycast hits a collider of a particular type, the code tells the object, and the object does whatever it is programmed for. If you want to detect in a cone fashion as you've asked:

  • 'player' is the transform of the player

  • 'object' is the transform of the object being tested

  • 'r' is the radius of the code

  • 'look 'is a direction vector of the center of the reticle. If you are constructing a ray from the mouse position, it will be the Ray.direction.


    var v = object.positon - player.position; var maxAngle = Mathf.ATan(r / v.magnitude) * Mathf.Rad2Deg;

    if (Vector3.Angle(look, v)

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 okletshavesomefun · Sep 11, 2018 at 08:34 PM 0
Share

Is that where it stops?

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to scale/calculate GameObject Z distance to the real physical world... 0 Answers

Movement with playmaker 0 Answers

Error downloading Unity 2 Answers

School Assessment 2 Answers

Volume detection. 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