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 Narv · May 30, 2015 at 01:53 PM · rotationcharactercontrollerplatformer

Rotate character in 3D platformer

Hey guys,

so I'm building a 3D (what I guess is 2.5D really) platformer but having a bit of trouble with the character control.

I am using basic shapes at the moment, so a capsule with a character controller on it, and some cubes for the level. I can move left and right, and jump just fine so the actual movement is not at all an issue. What I am unable to figure out (and may not be possible) is rotating the capsule (to be replaced with a model later) to look in the direction he's going. I tried googling, other answers on here, and youtube and can't seem to find one specific to my issue.

Here is what I have so far.

 public class PlayerController : MonoBehaviour {
 
     [Range(1.0f, 10.0f)]
     public float movementSpeed = 1.0f;
     [Range(1.0f, 15.0f)]
     public float jumpSpeed = 8.0f;
     [Range(1.0f, 30.0f)]
     public float gravity = 20.0f;
     private Vector3 moveDirection = Vector3.zero;
     private CharacterController controller;
 
     // Use this for initialization
     void Start () {
         controller = GetComponent<CharacterController>();
     }
     
     // Update is called once per frame
     void Update () {
         // if we are on the ground
         if(controller.isGrounded)
         {
             // we are on the ground so calculate the direction
             moveDirection = new Vector3(Input.GetAxis("Horizontal") * movementSpeed, 0, 0);
             moveDirection = transform.TransformDirection(moveDirection);
 
             // jump
             if(Input.GetButton("Jump"))
                 moveDirection.y = jumpSpeed;
         }
 
         // apply gravity
         moveDirection.y -= gravity * Time.deltaTime;
 
         // move 
         controller.Move (moveDirection * Time.deltaTime);
 
         // kill us at the bottom...
         if(transform.position.y <= -6)   
             transform.position = Vector3.zero;
     }
 }


I have tried a few different ways to change the character's rotation but none seem to work. I've used Quaternion.Slerp to the new rotation based off the moveDirection. I've tried altering the transform.rotation and eularAngles and just flat Transform.Rotate but they seem to all mess with the movement of the character controller.

My desired effect is that of a normal 2D platformer but in 3D (I also tried to look at the example given with Unity 5 in 2D but it just flips the scale which didn't work either). I want to be able to change the direction the character is facing but also make sure that the direction of the input doesn't change.

If I try to manually change the rotation in the inspector, the "d" key would normally make me go forward, now I travel backwards with the different rotation.

Thanks for the help guys.

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
Best Answer

Answer by Narv · Jun 01, 2015 at 04:14 PM

Found this question that had the correct answer:

http://answers.unity3d.com/questions/28109/how-to-turn-and-face-the-direction-im-moving-using.html

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

19 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

Related Questions

Player rotation not working correctly after using moving platform 0 Answers

Camera lock on enemy 0 Answers

CharacterController "breaks" collision, goes haywire 2 Answers

Character Controller change target direction in degree 1 Answer

rotate around character 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