Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 remoteplayfreak · Jun 01, 2011 at 09:39 PM · inputfpsmousesmoothjitter

Smoothen Mouse Axis Input

Hey Guys! I'm currently working on a FPS experimental hobby thingy, and i've run into problem recently:

To make the whole thing look more realistc i tried to implement the movement a weapon does in every normal FPS, where the weapon rotates up to a certain amount of degrees based on the speed of your input, f.e. the speed you're giving your mouse. At the moment i've got this code:

 private var start_rotation_y;
 
 function Start() {
     start_rotation_y = transform.localEulerAngles.y;
 }
 
 function FixedUpdate() {
     var mouseSpeedX:float = Input.GetAxisRaw("Mouse X");
     var speedRounded:float = Mathf.Round(mouseSpeedX * 3);
     transform.localEulerAngles.y = start_rotation_y + speedRounded;
 }

The problem with that is, that the weapon moves but the movement is very jittery, when I would rather have it being smooth and due to this realistic looking.

I've tried a few things, but they all ended up being jittery, so i hope someone in the community knows a proper fix for that!

Greets, remoteplayfreak!

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

Answer by testure · Jun 01, 2011 at 09:44 PM

I think that so long as you're mapping mouse input directly to your camera rotation, you're going to get some erratic behavior. have you considered doing a Quaternion.Slerp to smooth the values over time? Even if the time is as low as a tenth of a second it should reduce jittering considerably (because that's honestly how mouse smoothing works, it just averages your input over X amount of time).

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 remoteplayfreak · Jun 01, 2011 at 09:49 PM

I've actually tried to avoid Quaternions, because i prefer localEulerAngels, because we recently did that in school ;)

Nevertheless: Could you possibly tell me a little bit about Quaternions because i have no clue how to use them!

Comment
Add comment · Show 10 · 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 Johan 4 · Jun 01, 2011 at 09:54 PM 0
Share

Aren't eulerangles deprecated or something?

avatar image remoteplayfreak · Jun 01, 2011 at 09:55 PM 0
Share

what do you mean?

avatar image testure · Jun 01, 2011 at 09:59 PM 0
Share

You can still use euler angles- but a transform rotation is actually a Quaternion. Even if you're controlling it via localEulerAngles, that's still getting converted into a Quaternion in the long run.

desiredRotation = Quaternion.Euler(new Vector3(angleX, angleY, angleZ)); // where desiredRotation is a Quaternion transform.rotation = Quaternion.Slerp(transform.rotation, desiredRotation, Time.time * speed);

more info here: http://unity3d.com/support/documentation/ScriptReference/Quaternion.Slerp.html

also- post comments as comments, not as answers ;)

avatar image remoteplayfreak · Jun 01, 2011 at 10:01 PM 0
Share

Sorry, I've just started using Unity Answers, and i don't know where you live, but where I live, it's not that early anymore ;)

I've got just one question: in your "transform.rotation" row, what do you use as speed?

avatar image testure · Jun 01, 2011 at 10:16 PM 0
Share

speed is arbitrary.. it's however fast you want it to move. I'd suggest making it a public float, and then adjust the value in the inspector until it looks the way you want it to.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to create a old (2D style) fps cursor 3 Answers

Mouse input lag causes line rendering jitter 1 Answer

Unity Web Player does not respond to mouse clicks 1 Answer

How to disable mouse click detection in game when clicking exit menu button? 1 Answer

How to stop jitter with rigidbody2D 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