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 billymcguffin · Apr 18, 2011 at 01:36 AM · rotationjavascriptsnap

Rotation Jerks when Copying From Different Object

Hi all.

I have a character and a cameraPivot object. The camera pivot uses this modification of the 3rd person camera script:

function Update() { if(Input.GetKeyDown(KeyCode.LeftBracket)){ sensitivity --; } else if (Input.GetKeyDown(KeyCode.RightBracket)){ sensitivity ++; }

 if(sensitivity < 1){
     sensitivity = 1;
 }

 x += Input.GetAxis("MouseX") * sensitivity * 0.02;
 y -= Input.GetAxis("MouseY") * sensitivity * 0.02;

 if(y > capAmount){
     y = capAmount;
 } else if(-y > capAmount){
     y = -capAmount;
 }

 if(x >= 180){
     x -= 360;
 } else if(x <= -180){
     x += 360;
 }

 myTransform.rotation = Quaternion.Euler(y, x, 0);

}

As you can see, if the vertical rotation gets to 180 or -180 (turned completely around from the original rotation), it will change the rotation to be the same rotation but represented by a number in between 180 and -180.

The problem arises, however, when I try to make the character copy this rotation. When I press the W key, the character should rotate to face away from the camera (copies the y component of the camera pivot's rotation to the y component of the character's rotation). When the rotation gets to within about 10 degrees of 180 or -180, the character refuses to rotate until the rotation is outside of this 10 degree 'limit'. This causes the character to snap to the correct rotation after leaving the 'limit', which is quite undesirable.

I've tried using Lerp and Slerp to change the rotation, but that makes it worse.

Here's a video of my problem because my explanation sucked: http://www.youtube.com/watch?v=CbQx_Snzdek

Thanks to anyone who can help! :D

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 Jesse Anders · Apr 18, 2011 at 07:37 AM 0
Share

Does the code sample you posted include the code that's actually causing the problem?

avatar image billymcguffin · Apr 19, 2011 at 12:55 AM 0
Share

No, the code that causes the problem is this: transform.rotation.y = cameraTransform.rotation.y;

1 Reply

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

Answer by billymcguffin · Apr 19, 2011 at 01:03 AM

Ah, ok. I found the answer. I had to use rotation.eulerAngles.y, not rotation.y.

Solved.

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

Mouselook snapping. 0 Answers

Realtime Object Rotation on iPad 0 Answers

Smooth rotation in 90° increments 0 Answers

How To Check If X Rotation Is Between Two Numbers?? 1 Answer

space flying system 3 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