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 chaosblacklegion · Sep 07, 2020 at 08:23 PM · camera rotatecamera-lookroot motionstate-machinethirdpersoncontroller

Rotate character to camera orientation(direction camera is facing)

Im using root motion with a character controller ,current trying to have the character while moving to rotate in the direction the camera is facing(third person).

This is the code im using it works:

  public void CameraCharacterRotation()
 {
             float yawCamera = playerCamera.transform.rotation.eulerAngles.y;
             transform.rotation = Quaternion.Slerp(transform.rotation, 
             Quaternion.Euler(transform.rotation.x, yawCamera, 
             transform.rotation.z), turnSpeed * Time.fixedDeltaTime);
 }

It will rotate character to face camera direction will moving. The issue lies when i turn a character left /right/back

The code for that works as well:

 public void DirectionalRotation(float characterRotaionSpeed)
 {          
 
             //Converts playerInput.directionalInput(Vector2) to a Vector3 playerMovement, this will be used for the rotation of the 
             character,y is set to zero due as we only want to manipulate x and z axis
             playerMovement = new Vector3(playerSettings.DirectionalInput.x, 0f, playerSettings.DirectionalInput.y);
 
             //Gets the current rotation
             var currentRotation = transform.rotation;
 
             //Rotates the transform to look at the directional key pressed
             transform.LookAt(playerMovement + transform.position, Vector3.up);
 
             //Gets the new rotation after a key has been pressed
             var newRotation = transform.rotation;
 
             //Lerps the rotation from the charcters previous rotation(before key press) to its new rotation (after key pressed). You can 
             adjust characterRotaionSpeed to determine the speed of the rotation
             transform.rotation = Quaternion.Lerp(currentRotation, newRotation, characterRotaionSpeed);
 }

I call DirectionalRotation() in the MovementState

Root motion: private void OnAnimatorMove() { rootMotion += animator.deltaPosition; }

   private void FixedUpdate()
 {
  if (groundedPlayer && playerVelocity.y < 0)
 {
                 playerVelocity.y = 0f;
 }
             playerVelocity.y -= playerSettings.Gravity * Time.deltaTime;
 
             characterController.Move(rootMotion + playerVelocity);
             rootMotion = Vector3.zero;
 }

The code for the DirectionalRotation works and the code for CameraCharacterRotation works, but together they cause issues. The character will rotate in camera direction but the character will not rotate according to which movement direction is pressed.

Comment
Add comment · Show 1
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 chaosblacklegion · Sep 07, 2020 at 08:32 PM 0
Share

If i dont use root motion it is able to do what i need, but im trying with root motion, as for me it looks and feels better.

0 Replies

· Add your reply
  • Sort: 

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

138 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

Related Questions

Camera shaking on crouching and rotating player 0 Answers

Camera behaviour when looking directly up or down 0 Answers

problem with smooth camera look at target 0 Answers

Cinemachine input axis camera movement,cinemachine input axis control with script 1 Answer

How to make my Camera Controller look at target 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