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 LysolPionex · Nov 11, 2014 at 06:38 AM · rotationrollpitchyawglide

Adjust Yaw For A Gliding (Like Superman 64) Script

This is a little bit different of a setup from the question answered elsewhere in the forums. alt text

My character should glide like Superman, rolling and pitching with the joystick, and levelling when the joystick is neutral. (e.g. like this)

In addition, the character should rotate around the global Y-axis.

I am so close, but missing something, and I think I just need a fresh set of eyes. Currently, the pitch and roll behave properly, but I cannot figure out how to add the previous Y-axis rotation to accumulate the rotation:

 public void AdjustGlidePitchYawAndRoll(float pitch, float yaw, float roll, float speed)
 {
     Quaternion desiredRotation = Quaternion.Euler(new Vector3(0.0f, yaw, 0.0f)) *                 //I can't figure out how to add the previous yaw properly
                                  Quaternion.Euler(new Vector3(90.0f + pitch, 0.0f, 0.0f)) *       //90 degrees, to make the character prostrate by default, like Superman
                                  Quaternion.Euler(new Vector3(0.0f, roll, 0.0f));
     Quaternion rotationThisFrame = Quaternion.Slerp(transform.rotation, desiredRotation, speed * Time.deltaTime);

     transform.rotation = rotationThisFrame;
 }

This code will only rotate toward the current yaw passed in. How would I get the current yaw so I can increase it each frame? Simply using transform.eulerAngles.y does not work, because it can change depending on the pitch and roll.

I think what I ultimately want to do is use the current roll as a starting point, but I can only figure out how to start from the identity. :(

Here's a package that has my code thus far (GlideRotation1.cs is current code). Maybe someone can open it and see the simple fix for it... :-\

gliding pitch roll yaw.png (11.9 kB)
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

1 Reply

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

Answer by prof · Nov 11, 2014 at 08:57 AM

http://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html transform.eulerAngles.y + yaw in your case

Comment
Add comment · Show 7 · 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 LysolPionex · Nov 11, 2014 at 02:35 PM 0
Share

Thanks for contributing, prof! I tried using eulerAngles.y, but it doesn't quite cut it. I believe it would work if the character weren't pitching and rolling.

I also tried doing Translate.Rotate() for each axis, pitch and roll in Space.Self, and yaw in Space.World. I don't remember why that one didn't work. I'm at work at the moment, so I can't run the code now, but in about 9 hours, once I'm home, I'll try your solution and the Transform.Rotate(), and update this post.

avatar image LysolPionex · Nov 12, 2014 at 06:33 AM 0
Share

I cleaned up my question.

avatar image prof · Nov 12, 2014 at 07:15 AM 0
Share

This should give you idea (hopefully)

     float yaw = 0.0f;
     float pitch = 0.0f;
     float roll = 0.0f;
 
     float $$anonymous$$ax$$anonymous$$ch = 90.0f;
     float $$anonymous$$in$$anonymous$$ch = -30.0f;
     float $$anonymous$$axRoll = 30.0f;
 
     float RotSpeed = 25.0f;
 
     void Update () {
 
         pitch += Input.GetAxis("$$anonymous$$ch") * Time.deltaTime * RotSpeed;
         yaw += Input.GetAxis("Yaw") * Time.deltaTime * RotSpeed;
         roll += Input.GetAxis("Roll") * Time.deltaTime * RotSpeed;
 
         pitch = $$anonymous$$athf.Clamp(pitch, $$anonymous$$in$$anonymous$$ch, $$anonymous$$ax$$anonymous$$ch);
         roll = $$anonymous$$athf.Clamp (roll, -$$anonymous$$axRoll, $$anonymous$$axRoll);
 
         transform.rotation = Quaternion.Euler (pitch, yaw, roll);
     }


avatar image prof · Nov 12, 2014 at 07:17 AM 0
Share

code for learning purposes and unusable. Played Superman 64? Pretty much it)

avatar image LysolPionex · Nov 12, 2014 at 08:20 AM 0
Share

I want it to work exactly like superman 64! (Like this.)

I see where you're co$$anonymous$$g from, but it's not quite it. Here's a package with the method you coded and the method I coded (there are two scripts attached to the cube you can enable/disable).

This line: transform.rotation = Quaternion.Euler (pitch, yaw, roll);

won't work for my project, because of the order of rotation (yaw and roll effectively do the same thing; you can see this in the GlideRotation2 script).

In the same way, you can try adjusting the yaw in GlideRotation1.cs by using the current transform.eulerAngles.y, and see how weird the behavior gets! :)

So far, I am at a complete loss as to how to get this to work.

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

pitch yaw roll user input on an object? 2 Answers

pitch camera up and down... 1 Answer

Yaw, Pitch, Roll adjustments relative to object? 1 Answer

How to change angle-roll object with mobile input? 0 Answers

How to work out dogfight rotations for AI 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