• 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
Question by Dusty777 · Apr 07, 2017 at 02:49 PM · scripting problemmathcamera rotateangles

Clamp a Vector above minimum angle from another Vector?

I've got a weird one.

Seems basic, feels like it's got an elegant solution, but I can't figure it out...

I'm trying to create a function like:

 Vector3 FindsNearestPermittedVector 
 (Vector3 reference, Vector3 maybeReject, float minimumAngleAllowable)

Like say I'm trying to avoid any Vectors pointing within 30 degrees of Vector3.up.

And then say I start generating random vectors... If Vector3.Angle(randomVector, Vector3.up) < 30, then I don't want it! But then I also have to calculate an appropriate angle. That follow up is the hard part.

New angle, and in 3d that creates a cone

How to do??


Extra details:

It's like I need some kind of 3D Vector clamp cone. Where all angles are permitted except any that are within X degrees of a vector (so you get a forbidden cone). Well I mean, the forbidden area is easy to do. Just Vector3.Angle. But how do I find the nearest permitted point?

Right now I'm thinking of using a While loop to keep measuring Vector3.Angle ... and I suppose I could create AND rotate a gameobject's forward... until it's angle is > 30 degrees again.

Maybe that's it? Use gameObject manipulation in calculation. Just seems so messy.

Ps. The gist of what I'm doing is to have one "chasing" object (used for other calculations) maintain position directly behind another unless the runner goes straight upward.

Any ideas?

restrictioncone.jpg (321.6 kB)
Comment
leni8ec

People who like this

1 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Need help rendering Orbits, with Orbital Elements 1 Answer

Need help to get 3D rotation from 2 points in space 1 Answer

How to get the "Perfect" Sine Wave Pattern 2 Answers

how do i move a camera with mouse. 3 Answers

Calculating jump while rotating around pivot 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