Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
2
Question by Alavardo · Jul 22, 2011 at 04:54 AM · raycastcharacterdegrees

How to Raycast on 45 Degree?

Hello. I need 2 rays from character to left and the right in 45 Degree? How can i do that? Thanks.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
12
Best Answer

Answer by aldonaletto · Jul 22, 2011 at 05:26 AM

You can derive the +45 and -45 vectors just adding or subtracting transform.forward and transform.right:

   var right45 = (transform.forward + transform.right).normalized;
   // since transform.left doesn't exist, you can use -transform.right instead
   var left45 = (transform.forward - transform.right).normalized;
Comment
Add comment · Show 6 · 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 Alavardo · Jul 22, 2011 at 05:29 AM 0
Share

Thank you friend. You really help me!

avatar image Alavardo · Jul 22, 2011 at 05:32 AM 0
Share

One question, if that be 90 degree?

avatar image aldonaletto · Jul 22, 2011 at 06:21 AM 1
Share

If you want 90 degrees to the right, just use transform.right. For 90 degrees to the left, you can use -transform.right ("transform.left" doesn't exist in Unity, but in the vector world left is the same as -right)

avatar image aman_jha · Aug 16, 2016 at 06:48 PM 0
Share

@aldonaletto how would you use a custom angle, like 37.5 degrees to the left?

avatar image Bunny83 aman_jha · Aug 16, 2016 at 07:06 PM 1
Share
 var a = yourAngleInDegree * $$anonymous$$athf.Deg2Rad;
 var dir = (transform.forward * $$anonymous$$athf.Cos(a) + transform.right * $$anonymous$$athf.Sin(a)).normalized;

an alternative:

 var dir = Quaternion.Euler(0,yourAngleInDegree,0) * transform.forward;
avatar image elijahjns Bunny83 · Oct 09, 2020 at 03:57 AM 0
Share

var dir = Quaternion.Euler(0,yourAngleInDegree,0) * transform.forward; Failed for me.

var a = yourAngleInDegree $$anonymous$$athf.Deg2Rad; var dir = (transform.forward $$anonymous$$athf.Cos(a) + transform.right * $$anonymous$$athf.Sin(a)).normalized; ^^^^ Worked very well. Thanks!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

NullReferenceException help 1 Answer

Turn in the direction of movement 0 Answers

Raycast Drection change problem 0 Answers

Get GameObject to face and move towards Raycast hit point 1 Answer

What's a good way to find the ground normal? 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