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 PrinceAli · Jun 13, 2010 at 09:07 PM · rotationobjectfind

How do i GET the the YRotation of an object?

Hi, im just starting out. As the title says, i want to get the YRotation from the camera.

I think im supposed to use this?

YRot = GameObject.Find("Camera") . what here?

Thanks alot.

-Ali

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

3 Replies

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

Answer by PrinceAli · Jun 13, 2010 at 09:59 PM

Here is the complete script Movement1

var moveSpeed = 10.0; var XRot = 0; var fwd;

private var x : float; private var z : float; function Update () { z = Input.GetAxis("Vertical") Time.deltaTime moveSpeed; x = Input.GetAxis("Horizontal") Time.deltaTime moveSpeed;

fwd = Camera.main.transform.forward; fwd.y = 0; XRot = Vector3.Angle(Vector3.forward, fwd);

   // rotate the character based on the x value

//transform.Rotate(0, XRot, 0); transform.eulerAngles = new Vector3(0, XRot, 0);

   // Move the character forwards or backwards

transform.Translate(x, 0, z);

}

And here is the error: NullReferenceException: Object reference not set to an instance of an object Movement1.Update () (at Assets\MyScripts\Movement1.js:22)

Did i do it wrong?

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
avatar image
1

Answer by qJake · Jun 13, 2010 at 09:10 PM

YRot = GameObject.Find("Camera").transform.eulerAngles.y

will get you the 0-360 degree rotation of the camera (the same units that the Editor uses).

Comment
Add comment · Show 2 · 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 PrinceAli · Jun 13, 2010 at 09:13 PM 0
Share

Thanks alot mate =)

avatar image Mike 3 · Jun 13, 2010 at 09:16 PM 2
Share

Be careful if it's for anything important and you're not just rotating around Y, reading eulerAngles will (see$$anonymous$$gly) randomly flip 180 degrees

avatar image
0

Answer by PrinceAli · Jun 13, 2010 at 09:21 PM

I just noticed that it flips. So, im trying to make a simple 3rd person camera movement script.

var moveSpeed = 10.0; var XRot = 0;

private var x : float; private var z : float; function Update () { z = Input.GetAxis("Vertical") Time.deltaTime moveSpeed; x = Input.GetAxis("Horizontal") Time.deltaTime moveSpeed;

XRot=GameObject.Find("Camera").transform.eulerAngles.y; // rotate the character based on the x value transform.Rotate(0, XRot, 0); // Move the character forwards or backwards transform.Translate(x, 0, z);

}

But the players started to spin like crazy, what should i do? Im combining this script with the "MouseOrbit" script. Thanks

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

No one has followed this question yet.

Related Questions

Smooth camera rotation on mobile and pc when GetMouseButton()? 0 Answers

I can not I find an object hidden 2 Answers

Rotating Blender object using mouse click 1 Answer

Why won't my thing rotate faster 2 Answers

C# Make an object rotate along axis its moving on 0 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