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 /
This question was closed Jun 21, 2014 at 12:48 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by dom13 · Oct 12, 2011 at 01:50 PM · raycastplanerayslerplookrotation

Help with some C#

Hi,

I found this piece of code recently that tracks the mouse. There are some piece on the code that I would I am not 100% on and I would appreciate it if someone could help me understand them.

  • Quanternion.LookRotation

  • Quanternion.Slerp

  • Plane

  • Ray/Raycast

I have looked at the Unity code database, but I am struggling to understand what they do. I know Raycast intersects a plane and a ray and a ray is an infinite line, but thats about it.

Thanks

Comment
Add comment · Show 1
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 syclamoth · Oct 12, 2011 at 01:52 PM 0
Share

Well, I don't think I could explain it any better than the documentation does! $$anonymous$$ess around with some things, and get a feel for it if you are the type who learns better by doing.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by StewVanB · Jun 14, 2014 at 06:11 AM

Quaternion.LookRotation This function you supply a direction as a Vector3. This will rotate the object to "look" in the direction of the supplied vector.

Quaternion.Slerp This function you supply two rotations as Quaternions and a rate as a float. This will rotate the object from the first rotation towards the second rotation. The rate part is confusing to me the way it is written in the documentation. It's easier if you think of it as a "Slider" that starts at zero and goes to one. as the number in the rate gets closer to one the rotation gets closer to the second rotation. Example: //The start Rotation Quaternion from = transform.rotation; //The end Rotation Quaternion to = Quaternion.Euler(transform.forward);

         Quaternion.Slerp (from,to,0.0f);// 0.0% complete or Start rotation
         Quaternion.Slerp (from,to,0.1f);// 10.0% complete
         Quaternion.Slerp (from,to,0.9f);// 90.0% complete
         Quaternion.Slerp (from,to,1.0f);// 100.0% complete or End rotation
         
         //So in an update loop if you pass Time.time or some other counter
         Quaternion.Slerp (from,to,Time.time);//This will move from start to end as time passes.

Plane A plane is a plane. Not sure if this is what you were talking about.

Ray A ray is an infinite line from a point in a direction. As an example if you use Vector3.zero as your origin and Vector3.forward as your direction you will get a ray from zero to forward infinity.

RaycastHit This is used to take the information from what a raycast collided with.

Raycast A raycast is the operation of actually performing a cast of a ray you made.

LayerMask A layer mask is a nifty tool when used in combination with Raycasting. This allows you to set specific layers for your raycast to check against. For example if you want your ray to ignore things in the "Player" layer you would uncheck "Player" in your layermask variable.

Example:

         public LayerMask myLayerMask;
         
         void MyRayFunction(){
             Ray myRay = new Ray(Vector3.zero,Vector3.forward);
             RaycastHit rayHit;
             if(Physics.Raycast(myRay,out rayHit,100.0f,myLayerMask)){
                 //Do stuff if ray hit something
             }
         }


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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Math - calculate position in world space from ray on infinite plane 2 Answers

Trouble with Ray & Raycasting and AddForce() 1 Answer

Raycasting and foreach loops 1 Answer

how do i fix this small error 2 Answers

How can I apply damage based on a grenade explosion, but test whether the objects are behind cover so they are not damaged even within the explosion radius? 2 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