Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
1
Question by Johnny-Mapletree · Oct 17, 2021 at 08:00 PM · networkingvector3charactercontrollerphotonquaternions

Character controller won't rotate - Is it bad quaternion math or something else?

I'm trying to take an extant Character Controller asset and make it compatible with Fusion Networking - All I've done to make this work is modify the character controller script to accommodate fusion's network character controller rather than the default Unity character controller. Just passing inputs and adjusting little else, and the position and animation of the character now works with networking. But not rotation.

For whatever reason, the character controller will no longer turn in place despite the script logic being the same. Except, strangely, the script's logic for translating and rotating the character on moving platforms - Which utilizes quaternion math to determine the rotation and position to negate - works perfectly. If I manually set the player character to have an active platform 'beneath them' the quaternion math translates to the network character creator. But if they're not on a platform the logic doesn't pass, even though in both cases the "_moveDirection" vector is passed to the same character controller.

I've narrowed the problem down to this block of code; If the player's on a platform and not grounded, it accounts for the position of the platform. If they're not, it passes _moveDirection to the .move function of the character of the network character controller and suddenly that doesn't mean anything. ```

     //    //platforms
     if (!CurrentActivePlatform || !CurrentActivePlatform.CompareTag("Platform")) return;
     if (CurrentActivePlatform)
     {
         var newGlobalPlatformPoint = CurrentActivePlatform.TransformPoint(_activeLocalPlatformPoint);
         _moveDirection = newGlobalPlatformPoint - _activeGlobalPlatformPoint;
         if (_moveDirection.magnitude > 0.01f)
         {
             _controller.Move(_moveDirection);
         }

         if (!CurrentActivePlatform) return;

         //         // Support moving platform rotation
         var newGlobalPlatformRotation = CurrentActivePlatform.rotation * _activeLocalPlatformRotation;
         var rotationDiff = newGlobalPlatformRotation * Quaternion.Inverse(_activeGlobalPlatformRotation);
         // Prevent rotation of the local up vector
    

         rotationDiff = Quaternion.FromToRotation(rotationDiff * Vector3.up, Vector3.up) * rotationDiff;
        _characterTransform.rotation = rotationDiff * _characterTransform.rotation;
         _characterTransform.eulerAngles = new Vector3(0, _characterTransform.eulerAngles.y, 0);

         UpdateMovingPlatform();
     }
     else
     {
         if (!(_moveDirection.magnitude > 0.01f)) return;
         _moveDirection = Vector3.Lerp(_moveDirection, Vector3.zero, Time.deltaTime);
        _controller.Move(_moveDirection);
   
     }

     if (CanControl)
     {
         //        //this activate or deactivate jet pack Object and effect.
         JetPackObject.SetActive(Jetpack && _flyJetPack && JetPackFuel > 0 && !HoldingObject);

         if (_activeFall)
         {
             _slowFall = true;
             _activeFall = false;
         }

         if (HaveSlowFall && !_isGrounded && _slowFall)
         {
             SlowFall();
         }
         else
         {
             SlowFallObject.SetActive(false);
             _slowFall = false;
         }
     }
 

// camera = forward

     _forward = _cameraTransform.TransformDirection(Vector3.forward);
      _forward.y = 0f;
       _forward = _forward.normalized;
      _right = new Vector3(_forward.z, 0.0f, -_forward.x);

     _move = (_horizontal * _right + _vertical * _forward);
     _direction = (_horizontal * _right + _vertical * _forward);

 //    _move = (inputData.ninjaDirection.x * _right + inputData.ninjaDirection.y * _forward);
  //   _controller.transform.forward = _move;


     //    // //if no is correct grounded then slide.
     if (!_isCorrectGrounded && _isGrounded)
     {
        _move.x += (1f - _hitNormal.y) * _hitNormal.x * (1f - SlideFriction);
        _move.z += (1f - _hitNormal.y) * _hitNormal.z * (1f - SlideFriction);
     }

     _move.Normalize();
     //    // //move the player if no is active the slow fall(this avoid change the speed for the fall)
   if (!_slowFall && _controller.enabled)
     {
         _controller.Move(Time.deltaTime * RunningSpeed * _move);
     }

     //    // //Check if is correct grounded.
     _isCorrectGrounded = (Vector3.Angle(Vector3.up, _hitNormal) <= SlopeLimit);

``` I've pored over this code and it makes sense. I must be missing something - Is it just an issue of return; being called in the platform logic before the translation is passed...? should I be changing this vector math to account for quaternions instead...? I dread this being the case as I barely understand quaternions. I'm sort of new to C# so I could be missing something more fundamental.

This isn't a very specific question and I apologize for that, but I'm at the end of my rope. I don't understand what's not working here, when it works perfectly with a default character controller. Any help would be greatly appreciated.

Here is a video of the issue in action, perhaps that will help. Thanks for reading, either way! Wish me luck!

<

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 EvilBob99 · Oct 18, 2021 at 04:10 PM

now I don't know what any of this stuff is but I think rotating the transform point based on the platforms rotation should rotate it with the platform but you can also try momentarily parenting the object to the platform. hope this helps :)

Comment
Add comment · Show 2 · 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 EvilBob99 · Oct 18, 2021 at 04:13 PM 0
Share

also the video is pretty bad you can t see a thing -_-

avatar image EvilBob99 · Oct 18, 2021 at 04:55 PM 0
Share

also I recommend making a separate save of this to try because unity hates reverting some of this shit

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

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

PUN Spawn in VR mode not working properly 1 Answer

What's wrong with my script ? 0 Answers

Move ball player relative to camera rotation 1 Answer

CharacterController.Move called on inactive controller UnityEngine.CharacterController:Move(Vector3) how can i fix it ? 0 Answers

I get an error message every time i run this script? Any ideas? 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