• 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 LPGaming · Jan 16, 2013 at 10:16 AM · movementcharacter

Character Movement has no rotation

Trying to set up a script where the camera follows the player and is always looking ahead, at first I thought the camera wasn't moving, then I realized it was the player that wasn't rotation, how exactly could I make the player rotate while using the standard movement script from the reference?

 /// This script moves the character controller forward 
 /// and sideways based on the arrow keys.
 /// It also jumps when pressing space.
 /// Make sure to attach a character controller to the same game object.
 /// It is recommended that you make only one call to Move or SimpleMove per frame.    
 
 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Update() {
     var controller : CharacterController = GetComponent(CharacterController);
     if (controller.isGrounded) {
         // We are grounded, so recalculate
         // move direction directly from axes
         moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                 Input.GetAxis("Vertical"));
         moveDirection = transform.TransformDirection(moveDirection);
         moveDirection *= speed;
         
         if (Input.GetButton ("Jump")) {
             moveDirection.y = jumpSpeed;
         }
     }
 
     // Apply gravity
     moveDirection.y -= gravity * Time.deltaTime;
     
     // Move the controller
     controller.Move(moveDirection * Time.deltaTime);
 }


Because, From what I understand (Which I don't understand the Horrizonal and Vertical Movement thing, it's just moving it left/right forward/backwards, not moving it Forward and changing the angles, which is what I want to do. Honestly. I would rather my character always be moving forward and the way he is facing change.

Comment
Add comment · Show 5
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 fafase · Jan 16, 2013 at 10:21 AM 1
Share

Are you trying to do it for learning? Because you could use the Character Controller Assets which has all you need including a first or third person controller. What you are missing is the mouse script which control the orientation of the camera and the direction of the player.

avatar image LPGaming · Jan 16, 2013 at 10:51 AM 0
Share

I'm doing this mainly for learning, and because I don't like editing the provided scripts, which once i get my basic movement down I'm going to incorporate my abilities and skills to the movement modifier, I have abilities that should Speed Up and slow the character, I figured if I had my own handler for everything it would be easier in the long run, without completely destroying a reference that something already had.

I'm just trying to figure out how to rotate the character, rather then have it move with the Input.getAxis I don't want my character to move left and right, only rotate left and right and move forward, which I'm trying to figure out. I know how to use basic Transform.Rotate(0,0,0) but I don't want it to jump 90 degrees and keep going, I'd like to have it slowly rotate, perhaps 1-2 degrees at a time.

Thanks for your reply.

avatar image TRiToNDREyJA · Jan 27, 2013 at 11:26 PM 0
Share

try this. it works great for me:

function Update() { var speed : float = 5 transform.eulerAngles.y += (Input.GetAxis("Horizontal") * speed); }

avatar image TRiToNDREyJA · Jan 27, 2013 at 11:29 PM 0
Share

since your learning, ill explain it.

eulerAngles is rotation relative to its origin i think.

speed is the amount of degrees at a time.

when you press left or right, value is set to 1 or -1.

it is then multiplied by your speed then added to your eulerAngle rotation.

hop this helped :)

avatar image fafase · Jan 28, 2013 at 06:40 AM 0
Share

eulerAngles is the rotation as vector3. This is how Unity displays the rotation in the Inspector. Internally, it uses a Quaternion which uses 4 values and the last one is the rotation value.

EulerAngles are prone to error since one set can yield different results (but are 25% cheaper on memory). For instance if you rotate with eulerAngles of (1,1,1) constantly you expect the object to get back to (0,0,0) after 360 rotations. It won't.

On the other hand Quaternion works with a target vector rotation ins$$anonymous$$d so it appears smoother and avoid gimbal lock.

eulerAngles is just a more human way to consider rotation but is not 100% error proof, while Quaternion requires a Phd in Physics to understand what the w really is for (complex number).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Jan 16, 2013 at 11:14 AM

If you want to rotate, add a line with

 float speed = aValueYouGive;
 transform.Rotate(Vector3.up * Time.deltaTime*Input.GetAxis("Horizontal")*speed);

the also remove the Input.GetAxis("Horizontal") in moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,Input.GetAxis("Vertical"));

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

wanna know what make my char stop 0 Answers

Character Controller problem 0 Answers

How to handle walls with my FirstPersonCharacter? 1 Answer

How to prevent rigidbody with capsule collider from walking off the edge of cube mesh if button held down? 1 Answer

Non-symmetrical Character walk left animation. 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