Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
  • Help Room /
avatar image
1
Question by Kennyist · Mar 13, 2013 at 04:54 PM · c#rotationvector3vectortransforms

Vector3 and transform.rotation?

Hi,

I'm trying to do a simple reset players position, I've got it all working apart from the players rotation. I'm trying to use a vector3 but I keep getting this error "OutOfZone.cs(24,34): error CS0029: Cannot implicitly convert type UnityEngine.Vector3' to UnityEngine.Quaternion'"

 public class OutOfZone : MonoBehaviour {
     
     public Transform Player;
     public Vector3 coOrds;
     public Vector3 view;
     public AudioClip fallSound;
     public AudioClip goBackSound;
     
     void OnTriggerEnter (Collider col) 
     {
         StartCoroutine(outZone());
     }
     
     IEnumerator outZone()
     {
         CameraFade.FadeOutMain();
         audio.PlayOneShot(fallSound);
         yield return new WaitForSeconds(2);
         audio.PlayOneShot(goBackSound);
         Player.transform.position = coOrds;
         Player.transform.rotation = view;
         yield return new WaitForSeconds(1);
         CameraFade.FadeInMain();        
     }
 }

What do I use to get this to work?

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

2 Replies

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

Answer by CHPedersen · Mar 13, 2013 at 04:59 PM

The problem is pretty much exactly what the error says. :) In this line:

 Player.transform.rotation = view;

You are attempting to set the rotation to the variable view, but view is of type Vector3, and the rotation of a Transform is of type Quaternion. Those types are incompatible - you can't set it like that. You have to either set the rotation using a Quaternion you create with the Quaternion constructor directly, or by creating a quaternion using one of the static methods in class Quaternion.

For example, since you're storing view as a Vector3, maybe I can assume you're actually storing the degrees of rotation around x, y and z in view.x, view.y and view.z? In that case, you can set your rotation like this:

 Player.transform.rotation = Quaternion.Euler(view.x, view.y, view.z);
Comment
Add comment · Show 4 · 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 robertbu · Mar 13, 2013 at 05:11 PM 1
Share

Or you can just set it like:

 Player.transform.eulerAngles = view; 
avatar image Kennyist · Mar 14, 2013 at 10:23 AM 0
Share

Thanks, Didnt know what a quaternion was since i've never seen it before in this. But that worked fine.

avatar image CHPedersen · Mar 14, 2013 at 10:41 AM 0
Share

It's a matrix used to store rotations in a way that avoids Gimbal lock. $$anonymous$$ore on that on Wikipedia. If the reply helped you, please consider marking it correct. :)

avatar image Px_Extant · Sep 23, 2015 at 12:24 PM 0
Share

I did'n get the error rigth but now i get it thanks!

avatar image
0

Answer by KingKong320 · Jun 25, 2019 at 04:41 AM

i have tried eulars is vector3 type. transform.rotation = Quaternion.Euler (eulars.x, eulars.y, eulars.z); but it gives error Assertion failed on expression: 'CompareApproximately(SqrMagnitude(result), 1.0F)' UnityEngine.Quaternion:Euler(Single, Single, Single).

Please help me out.

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

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

14 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

Related Questions

Help with raycast for for wall detection 1 Answer

How to rotate the player towards a Vector2? 1 Answer

I want to make a script that causes the directional light to stop at 180 degrees. 0 Answers

Problem getting Vector3.Slerp to rotate in the correct direction in specific situation 0 Answers

Searching a function to get the rotation of one Vector3 in relation to another 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