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 steveyj91 · Dec 09, 2016 at 06:17 AM · rotation3dvideocharacter controllerarc

3d Character rotates in an arc rather than on the spot [video attached]

I've been stuck on this problem for a while and haven't found anyone having similar difficulties. Basically I have a 3rd person character that I am trying to get to move and rotate at the same time. My character moves and rotates to begin with OK, but eventually the character starts to rotate in huge arcs which you can see in the attached video. Any help on this would be appreciated as I've spent too many hours now without getting anywhere.

Here is the video

and here is my code

      public float speed = 2.0F;
      public float jumpSpeed = 1.0F;
      public float gravity = 50.0F;
      public float turnSmoothing = 15f;
      public float lookSpeed = 100;
  
      public Vector3 moveDirection;
  
      public float moveHorizontal;
      public float moveVertical;
  
      public int grounded = 1;
      public Transform head;
      public Transform groundcheck;
  
  
      float GroundDistance = 0.5f;
  
      bool IsGrounded()
      {
          return Physics.Raycast(groundcheck.position, -Vector3.up, GroundDistance);
      }
  
      void Update()
      {
  
          moveHorizontal = Input.GetAxisRaw("Horizontal");
          moveVertical = Input.GetAxisRaw("Vertical");
  
          moveDirection = new Vector3(moveHorizontal, 0, moveVertical);
          moveDirection = Camera.main.transform.TransformDirection(moveDirection);
  
          ConstantForce headcf = head.GetComponent<ConstantForce>();
  
          CharacterController controller = GetComponent<CharacterController>();
  
          if (controller.isGrounded)
          {
              
              if (Input.GetButton("Jump"))
              {
                  if (IsGrounded() == true)
                  {
                      moveDirection.y = jumpSpeed;
                      headcf.force = new Vector3(0, 180, 0);
                      print("Ground");
                      grounded = 1;
                  }
                  else
                  {
                      headcf.force = new Vector3(0, 60, 0);
                      print("Not Ground");
                      grounded = 0;
                  }
                  
              }
  
          }
  
          moveDirection.y -= gravity * Time.deltaTime;
          controller.Move(moveDirection * Time.deltaTime);
  
          if (moveHorizontal != 0f || moveVertical != 0f)
          {
              Rotating(moveHorizontal, moveVertical);
          }
      }
  
      void Rotating(float mh, float mv)
      {
  
          Vector3 targetDirection = new Vector3(mh, 0f, mv);
  
          Quaternion targetRotation = Quaternion.LookRotation(moveDirection, Vector3.up);
  
          moveDirection.y = 0f;
  
          Quaternion newRotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSmoothing * Time.deltaTime);
  
          transform.rotation = newRotation;
      }


Comment
Add comment · Show 2
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 DoubleIsLoveDoubleIsLife · Dec 09, 2016 at 08:48 AM 0
Share

If the character is a child of another object make sure it's local position is set to 0,0,0. Also make sure the models pivot point is centered.

avatar image Cherno · Dec 09, 2016 at 03:10 PM 0
Share

Why does the Rotating method take movement values as parameters?!?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by steveyj91 · Dec 09, 2016 at 05:08 PM

Thanks @DoubleIsLoveDoubleIsLife , I've just looked at that and the local position of the metarig is set to 0,0,0. I imported the model from blender so could a pivot point be off from my imported model? I'll go back and check.

@Cherno Yeah that doesn't need to happen anymore as they were used in a previous version.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotating doesn't work correctly? 2 Answers

How to make a human character model grab a random moving object? 0 Answers

How to lock a transform's local up axis rotation on any surface 1 Answer

Mouse axes based on position, not movement. 1 Answer

Rotate back and forth around pivot 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