• 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 JacobM · Feb 13, 2014 at 02:46 PM · rotationmovementcharactercontrollerthird-person

CharacterController.move doesn't seem to move me horizontally

The following code is in a script that I'm calling ThirdPersonMovement. All I really want to accomplish is some simple character-controller based movement with a third person camera.

     public float movementSpeed;
 
     private CharacterController controller;
     private Vector3 cameraForward;
     private Vector3 cameraRight;
     private Vector3 DirectonToMove;
     private Transform mainCamTransform;
     
     void Start ()
     {
         controller = gameObject.GetComponent<CharacterController>();
         mainCamTransform = Camera.main.transform;
     
     }
 
     void Update ()
     {
         UpdateDirectionToMove();
         transform.rotation = Quaternion.LookRotation(cameraForward);
         controller.Move(DirectonToMove * movementSpeed * Time.deltaTime);
     }
 
     void UpdateDirectionToMove()
     {
         cameraForward = mainCamTransform.TransformDirection(Vector3.forward);
         cameraForward.y = 0;
         cameraForward = cameraForward.normalized;
 
         cameraRight = mainCamTransform.TransformDirection(Vector3.right);
         cameraRight.y = 0;
         cameraRight = cameraRight.normalized;
 
         DirectonToMove = Input.GetAxis("Horizontal") * cameraRight + Input.GetAxis("Vertical") * cameraForward;
         Debug.Log(DirectonToMove);
     }

I want the player to always be facing forward with respect to the camera's forward-facing direction, and currently this is happening correctly. The issue I am having is that I can't seem to move in a direction I am not facing. If I replace "transform.roation = Quaternion.LookRotation(cameraForward);" with the line "transform.rotation = Quaternion.LookRotation(DirectionToMove);" I can move in any direction I please - but I don't get the rotation I want. Any ideas?

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 robertbu · Feb 13, 2014 at 04:10 PM 0
Share

I ran a quick test. Your code worked fine for me. Any chance you have a game object with a collider childed to the character controller object?

avatar image JacobM · Feb 16, 2014 at 08:15 PM 0
Share

Thanks! That was exactly the problem. Although, I'm a little confused as to why colliders which are childed to a moving controller are "hitting" that controller...

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

18 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

Related Questions

Character Controller - unknown rotation, flying 1 Answer

Character Controller slides sideways when it hits objects are angles different from 90 degrees 1 Answer

How do i rotate based on direction character is moving in 1 Answer

How can I move a character to a point in a straight line with CharacterController.Move while rotating him? 2 Answers

AI Character not rotating when spawned in 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges