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
1
Question by DaveA · Nov 15, 2010 at 09:38 PM · fpsresetroll

Need to 'un-roll' my FPS

I'm using a FPS script for general navigation, but also have a 'tour' script which moves my player (and cam) around to some pre-defined views. In doing so, sometimes a 'roll' angle is introduced (for the nice view).

When the user moves the player (say, with mouselook or WASD), I want to remove any 'roll' that might have been introduced, leaving just pitch and yaw. Any ideas the best way to do this?

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
1
Best Answer

Answer by Jesse Anders · Nov 15, 2010 at 11:31 PM

You can apply a corrective rotation that aligns the object's up vector with the world up vector. This can be easily done in Unity using Quaternion.FromToRotation().

That said, an even easier solution would be to use a control scheme that doesn't introduce perceived roll in the first place. (I don't know what control scheme you're using currently, so I can't be much more specific than that.)

[Edit: Adding additional info following comments.]

Here is what I'd probably try:

  1. At the moment the user provides input while the camera is in 'tour' mode, grab the camera's orientation and store it.

  2. To 'correct' the camera's orientation, I think what you'll want to do is adjust it so that the camera's side vector lies in the XZ plane (assuming y is up). One way to do this would be to project the side vector onto the XZ plane, normalize the result, and then apply a corrective rotation (as I mentioned earlier) to rotate the current side vector onto the 'corrected' side vector. Note that cases where the projection has small magnitude (such as when the camera is on its side, more or less) will need to be handled separately.

  3. Once you have the corrected orientation, you can compute the yaw and pitch directly from the forward vector. At this point you can switch over to your standard yaw/pitch-based FPS-style control.

  4. Presumably you won't want this to happen instantaneously, as that would be a little jarring, but what you can do to smooth out the effect is interpolate between the last orientation for the 'tour' camera (which you saved in step 1) and the current orientation of the camera over some short interval.

I haven't actually tried the above myself, so it's somewhat speculative. But, it's probably what I'd try first.

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 Novodantis 1 · Nov 15, 2010 at 11:33 PM 1
Share

I think he is saying that the 'tour' scripts, from which the player sometimes resumes control, can introduce a roll rotation

avatar image DaveA · Nov 15, 2010 at 11:57 PM 0
Share

Correct. Basically I place a bunch of 'dummy' cameras which provide various useful and nice views of the scene. On command, I 'fly' the player using a type of SLERP to match one of those cameras. Sometimes there is a tilt involved because it just looks better. When they hit W or move mouse (for example), I need to upright the camera, not change pitch or yaw though, so it picks up pretty much where the 'tour view' left off, but without the tilt/roll that makes it look lame.

avatar image Jesse Anders · Nov 16, 2010 at 04:43 AM 0
Share

I edited my answer and added some additional info.

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

How do I put a delay on a gunshot? 2 Answers

Attach a animation to 0 Answers

about animation tab ? 1 Answer

FPS mouse look script error unity 3d. help!!!! 2 Answers

How to make a image flash infront of the camera 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