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 Jaxawesome22 · Mar 18, 2014 at 06:00 AM · cameracharactercontrollerrotate

Rotating Object with Mouse Axis is very choppy

I am trying to create this very simple controller for my character to move using velocity and to rotate the camera and character with the mouse. I am making a FPS and am looking for a feel similar to COD as far as character controls go. My problem thus far is that the rotation of the character and camera are very choppy and jumpy. It appears that it makes minor movements and jumps straight back to the original position. I realize that it may be very simple, but i have been struggling with solving it for the last few days. Any tips are greatly appreciated! rotate the camera

     public class PlayerControls : MonoBehaviour {
     
         public float moveSpeed, Sensitivity;
     
         void Start(){
     
         }
         // Update is called once per frame
         void Update () {
     
             rigidbody.transform.rotation = Quaternion.Euler(-Input.GetAxis ("Mouse Y") * Sensitivity, -Input.GetAxis ("Mouse X") * Sensitivity, 0);
             rigidbody.velocity = new Vector3(Input.GetAxis ("Horizontal") * moveSpeed,0,Input.GetAxis ("Vertical") * moveSpeed);
     
         }
     }
 
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

Answer by robertbu · Mar 18, 2014 at 06:14 AM

I'm not sure of your ideal rotation, but replace your Update() with the following for a smoother rotation:

 void FixedUpdate () {
     euler.x += Input.GetAxis ("Mouse Y") * Sensitivity;
     euler.y -= Input.GetAxis ("Mouse X") * Sensitivity;
     rigidbody.transform.rotation = Quaternion.Euler(euler);
     rigidbody.velocity = new Vector3(Input.GetAxis ("Horizontal") * moveSpeed,0,Input.GetAxis ("Vertical") * moveSpeed);
 }
Comment
Add comment · Show 6 · 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 Jaxawesome22 · Mar 18, 2014 at 05:11 PM 0
Share

That worked great thanks! Do you happen to know how i would make it so the up/down rotation won't spin all the way around? That way it will be more like the player looking up and down and not actually doing flips.

avatar image Jaxawesome22 · Mar 18, 2014 at 05:32 PM 0
Share

I am also having trouble aligning the velocity with the object rotation. Right now it is moving in the same direction regardless what direction the object is facing. Any suggestions?

avatar image robertbu · Mar 18, 2014 at 07:03 PM 0
Share

To limit the rotation, just clamp the values in 'euler' before assigning them the rotation. Example:

  euler.x = $$anonymous$$athf.Clamp(euler.x, -90, 90);

As for the movement direction, your current code does not take into account any form of direction. Try changing line 5 to:

 rigidbody.velocity = transform.forward * Input.GetAxis ("Vertical") * moveSpeed);
avatar image Jaxawesome22 · Mar 18, 2014 at 07:42 PM 0
Share

Thanks a ton! Im pretty new to this and you've been a great help!

avatar image Jaxawesome22 · Mar 18, 2014 at 07:47 PM 0
Share

I have one more problem! i think im missing something obvious but i can't move forward or back while right and left work perfectly, and my rotation still goes all the way around

public class PlayerControls : $$anonymous$$onoBehaviour { public float moveSpeed, Sensitivity; Vector3 euler; void Start(){ } // Update is called once per frame void FixedUpdate () { euler.y = $$anonymous$$athf.Clamp (euler.y, -90,90); euler.x -= Input.GetAxis ("$$anonymous$$ouse Y"); euler.y += Input.GetAxis ("$$anonymous$$ouse X"); rigidbody.transform.rotation = Quaternion.Euler(euler * Sensitivity); rigidbody.velocity = transform.forward * Input.GetAxis ("Vertical") * moveSpeed; rigidbody.velocity = transform.right * Input.GetAxis ("Horizontal") * moveSpeed; } }

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

20 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

Related Questions

Rotate Character Controller Camera 0 Answers

Object rotates with camera 2 Answers

Rotating Camera on Touch 1 Answer

Is there a way to make a Character Controller stop instead of move over obstacles?? 1 Answer

Camera won't rotate with parent object(Player) 2 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