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 Borzi · Jul 26, 2013 at 11:54 AM · c#javascripttranslateconversion

Converting Variable to C#

Could someone Translate this line of code to C# for me please?

 var hitRotation = Quaternion.FromToRotation(Vector3.up, Hit.normal);

Thanks!

Comment
Add comment · Show 2
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 Sephius · Jul 26, 2013 at 12:01 PM 0
Share

I'm not sure, but :

     Vector3 up = new Vector3(0,0,0);
     Vector3 hit = new Vector3(0,0,0);
     Quaternion hitRotation = new Quaternion(0,0,0,0);
     hitRotation.SetFromToRotation(up, hit);
avatar image perchik · Jul 26, 2013 at 06:25 PM 0
Share

Just so you know, Vector3.up is a specific vector that points straight up, not a new vector called "up", with the values of (0,1,0). (Vector3.forward, back, down, left, right are all similarly defined vectors).

1 Reply

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

Answer by moonstruck · Jul 26, 2013 at 11:57 AM

It is a valid C# code line (if you have variable Hit defined).

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 Bunny83 · Jul 26, 2013 at 12:33 PM 1
Share
  • exactly, but if you want to explicitly declare the variable type (ins$$anonymous$$d of type inference), it should look like this:

       Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, Hit.normal);
    
    

The variable "Hit" should be of type "RaycastHit".

avatar image Borzi · Jul 26, 2013 at 05:39 PM 0
Share

Okay I think its working if you put Quaternion in front of it thank you...just as a small question I know it's a different question but can someone tell me what variable type it is hier:

 var DirectionRay = transform.TransformDirection (Vector3.forward);

It would really help me out :)

avatar image tw1st3d · Jul 26, 2013 at 05:41 PM 2
Share

I think that would be a Vector3 variable.

avatar image Borzi · Jul 26, 2013 at 05:54 PM 0
Share

Great thank you all very much! I have to get used to moving from Java to C# :)

avatar image perchik · Jul 26, 2013 at 06:28 PM 0
Share

The best way to figure this out yourself is to look up the function in unity docs. Here's the function you just asked about. $$anonymous$$ake sure that the reference language is set to c# in the drop down box. At the top of the page it has this line:

 Vector3 TransformDirection(Vector3 direction)
 

Which explicitly says that it takes in a Vector3 for direction and outputs a Vector3.

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

21 People are following this question.

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

Related Questions

java to C# conversion 1 Answer

js conversion to c#. no errors but still not working 1 Answer

Help with conversion from javascript to c# 3 Answers

Multiple Cars not working 1 Answer

Translate C# into Js 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