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 RoDeLoPo · Oct 08, 2011 at 09:50 PM · rotationcharactercharactercontrollercontroller

Character Controller Rotation

So, in my game, I created a character, and I want to use "Character controller" to move it. It is moving fine, but I can't rotate it. Actually, I am being able to rotate it using transform.Translate, but that doesn't affect the way I move my character with Character Controller, so it always moves foward, backward, left or right whithout taking in consideration it's roation. Basicly, even though I rotate the character around, it move around as if it wasn't rotating. Sorry if this is an obvious and stupid question, but I am very new to Unity and scripting. Thanks!

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

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by aldonaletto · Oct 08, 2011 at 10:02 PM

You should not move with Translate, since collisions are not detected - you should use CharacterController.Move instead.
This is a simple script that I've adapted from the CharacterController.Move example to rotate instead of just go right and left. It's very simple, and you can modify it easily if you want to add new features:

var speed : float = 6.0; var jumpSpeed : float = 8.0; var turnSpeed : float = 60; var gravity : float = 20.0;

private var moveDirection : Vector3 = Vector3.zero; private var controller: CharacterController;

function Start(){ controller : CharacterController = GetComponent(CharacterController); }

function Update() { var turn: float = Input.GetAxis("Horizontal"); transform.Rotate(0, turn turnSpeed Time.deltaTime, 0); if (controller.isGrounded) { moveDirection = transform.forward Input.GetAxis("Vertical") speed; if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; } } // Apply gravity moveDirection.y -= gravity Time.deltaTime; // Move the controller controller.Move(moveDirection Time.deltaTime); }

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
avatar image
2

Answer by unity_QjPE1Ur0mLEAlA · Jun 05, 2019 at 09:28 PM

Ok this post is realy old, but I found a solution to rotate your character Controller with translate!


All you need to do is to rotate your object with translate:

 transform.eulerAngles = new Vector3(0, yourRotation, 0);


and Apply to your Move direction the "new Transformed Direction" with:

 moveDirection = transform.TransformDirection(moveDirection);


at the end you apply the moveDirection to your Character controller:

 controller.Move(moveDirection * Time.deltaTime);


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
avatar image
1

Answer by Sord · Feb 20, 2013 at 11:22 AM

Also this is NOT working:

 transform.rotation.SetLookRotation(moveDirection);

Insted use like this:

 Quaternion rot = new Quaternion();
 rot.SetLookRotation(moveDirection);
 transform.rotation = rot;
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 minjun · Sep 09, 2015 at 04:22 AM 0
Share

Thanks for your code. I find it cannot lock the rotation Direction when moving; if you release the move direction, the rotation direction will be reset to the original.

avatar image
0

Answer by dweitkunat · Oct 09, 2011 at 12:10 AM

You should make sure you're passing Space.self as the second argument to transform.Translate, otherwise the object will move in world space, regardless of rotation.

Always remember there are two coordinate systems to deal with: Global and Local.

Global axis directions never change, but local axis directions change with rotation.

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

7 People are following this question.

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

Related Questions

How to fix a infinity jump? 1 Answer

Face Direction Movement using CharacterController 1 Answer

fps script not working 1 Answer

rotate player towards the mous 1 Answer

Help with my Character Controller 1 Answer


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