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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Zaffer · Jul 29, 2014 at 04:44 PM · rotationcharacter controller

character controller rotation won't accept script values

Hi,
I am trying to set the character controller rotation by script so that the controller will move along that angle on play. I can script the values OK, but when I play the scene, the x and z values of the character controller's rotation always revert back to 0. Is there any way to work around this? Example code:

 var rot : Quaternion = Quaternion.LookRotation(dir);
     this.transform.rotation = rot;


Same thing happens if I set the rotation manually:

 this.transform.eulerAngles = new Vector3(10, 45, 150);

On play, the Y value will be 45, but the x and z will revert to zero. Any help will be greatly appreciated.

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
0
Best Answer Wiki

Answer by Zaffer · Jul 30, 2014 at 02:59 PM

I discovered the problem. It's in the MouseLook script, specifically, the line:

transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);

I don't really understand why, but this code causes the X value of the object to revert to zero when play starts, overriding any scripted value for X. (The Z value is not a factor as that is constant at zero.) I found a workaround by commenting out all the code in the MouseXAndY Axes choice and substituting this one line of code which does not use EulerAngles.

 transform.Rotate(-Input.GetAxis("Mouse Y") * sensitivityY, Input.GetAxis("Mouse X") * sensitivityX, 0);

Zaffer

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
0

Answer by ado112 · Jul 29, 2014 at 04:57 PM

Have you tried to use transform.rotation?

Comment
Add comment · Show 3 · 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 Zaffer · Jul 29, 2014 at 06:26 PM 0
Share

Thanks, but I thought that was what I was doing with the line:

 this.transform.rotation = rot;

transform.rotation needs a Quaternion, transform.eulerAngles takes a Vector3 number. As far as I can tell, the character controller ignores x and z values for both. Anybody else have a suggestion?

avatar image ado112 · Jul 29, 2014 at 07:20 PM 0
Share

i mean: transform.rotation.x = 10; transform.rotation.z = 150;

avatar image Zaffer · Jul 29, 2014 at 08:47 PM 0
Share

Thanks Ado, I tried that, but same result, x and z were reset to zero :-(

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

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

Related Questions

Mouse Look Script Acts Weird When Deactivated By Script 0 Answers

Is there a way to get the character controller to rotate? 0 Answers

Character Controller strange collision bug 2 Answers

How to Prevent Character Bouncing 0 Answers

Lock Z Rotation. Character Controller. 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