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 JenoahKers · Apr 28, 2018 at 07:02 PM · movementmovement scriptthird person controller

3rd person character spinning fast when rotating while standing still

Hi everybody,

I've got a little problem. Whenever my character moves position (like walking), the rotation works like it should. But whenever the character tries to rotate whenever it isn't moving, it spins out like crazy. This also happens whenever it tries to walk backwards.

It seems that whenever it rotation while not moving, it turns 90 degrees (everytime the rotation is being called) and 180 degrees when trying to walk backwards.

I do have a character controller attached with the default settings and I'm using the following script.

 public class ThirdPersonMoveScript : MonoBehaviour
 {
     public float walkSpeed = 3f;
     public float runSpeed = 6f;
     public float mouseSenitivity = 100f;
     private Vector3 moveDirection = Vector3.zero;
 
     void Update()
     {
         CharacterController controller = GetComponent<CharacterController>();
         moveDirection = new Vector3(Input.GetAxis("Mouse X") * mouseSenitivity, 0, Input.GetAxis("Vertical"));
         
         moveDirection = transform.TransformDirection(moveDirection);
         if (Input.GetKey(KeyCode.LeftShift))
         {
             moveDirection *= runSpeed;
         }
         else
         {
             moveDirection *= walkSpeed;
         }
 
         if (moveDirection != Vector3.zero)
         {
             //transform.rotation = Quaternion.LookRotation(moveDirection);
             controller.transform.rotation = Quaternion.LookRotation(moveDirection);
         }
         controller.Move(moveDirection * Time.deltaTime);
     }
 
 }
 



Is anyone familiar with this problem?
Thanks upfront,
Jenoah

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 Eno-Khaon · Apr 28, 2018 at 07:56 PM

 controller.transform.rotation = Quaternion.LookRotation(moveDirection);


By having your character attempt to face the direction they're moving, this causes them to turn around and face that way while attempting to move backwards. Because the direction you're moving at this point will keep changing relative to the direction you're now facing, you will wind up spinning wildly (at best) by attempting to move backwards.

Furthermore, when not moving, Unity's struggling/failing to determine a proper facing when the LookRotation vector provided is (0, 0, 0).

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

125 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How to disable A, S, and D keys for third person player movement 1 Answer

Why does my character constantly move forward and also at the start jump up into the air in a way?,Why does my character constantly go forward and goes up when starting ? 0 Answers

Slowly move a GameObject on 1 axis, then destroy it. 1 Answer

2D Topdown Character Contoller 0 Answers

Slime script? 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