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 Shiruba · Dec 09, 2020 at 03:28 AM · third-person-controller

Weird Behaviour with brackeys third person tutorial

Hi!

I followed Brackey's Third Person Controller tutorial perfectly and indeed everything is mostly working.

I noticed a strange behavior where when turning to left and moving the camera at the same time (Like strafing sideways while pointing to a target) the character will spin forever.

I managed to narrow the problem to some type of issue with Math, SmoothDamp and the way Unity deals with angles, because only turning left and sometimes backpedaling has this issue, turning right and walking forward works perfectly 100% of the time.

Can someone help me fix this?

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 Konomira · Dec 09, 2020 at 12:08 PM 1
Share

Can you show the code that you have written?

avatar image Shiruba Konomira · Dec 10, 2020 at 11:46 AM 0
Share

Sure!

Also, an update: The problem is less frequent since I wrote a method that gets an angle and constrains it to the -180 to 180 range , for example an input angle of 225 returns -135.

I still get spins, but usually one or two spins and not infinite spins, but I still would like to know what is happening.

  void Update()
     {
         //jump
         isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, ground$$anonymous$$ask);
 
         if (isGrounded && velocity.y < 0)
         {
             velocity.y = -2f;
         }
 
         if (Input.GetButtonDown("Jump") && isGrounded)
         {
             velocity.y = $$anonymous$$athf.Sqrt(jumpHeight * -2 * gravity);
         }
         //gravity
         velocity.y += gravity * Time.deltaTime;
         controller.$$anonymous$$ove(velocity * Time.deltaTime);
         //walk
         float horizontal = Input.GetAxisRaw("Horizontal");
         float vertical = Input.GetAxisRaw("Vertical");
         Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
 
         if(direction.magnitude >= 0.1f)
         {
             float targetAngle = $$anonymous$$athf.Atan2(direction.x, direction.z) * $$anonymous$$athf.Rad2Deg + cam.eulerAngles.y;
             float angle = $$anonymous$$athf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
             transform.rotation = Quaternion.Euler(0f, angle, 0f);
 
             Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
             controller.$$anonymous$$ove(moveDir.normalized * speed * Time.deltaTime);
         }
     }

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Shiruba · Dec 10, 2020 at 01:25 PM

@logicandchaos

I'm using 2020.1.3f1 Tutorial is 2019.3.9f1

Will try to mess around with magnitude, thanks.

Comment
Add comment · Show 1 · 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 Shiruba · Dec 14, 2020 at 12:09 PM 0
Share

OK GOT IT

The problems comes from the use of SmoothDamp to smooth the angles, the math function has no idea that angles after 180 should be -180 and so on, everytime the function has to smooth between positive and negative values, it "turns around" and takes the long way to the desired number.

Using Quaternion.Lerp solved everything!

avatar image
0

Answer by logicandchaos · Dec 10, 2020 at 12:07 PM

You can try adjusting this value: if(direction.magnitude >= 0.1f) try making it .25f and other values see if it helps. What version of unity was used in the tutorial and what version are you using?

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

140 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 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

TPS Camera Help 2 Answers

3rd Person Controller - Control Inputs 1 Answer

ThirdPersonController Player spins on axis joypad input. 1 Answer

3rd person shooter movement issues 1 Answer

Climb Wall: How do I change key input from horizontal to vertical? 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