Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 NunyoBusiness · Jan 25, 2014 at 08:09 PM · charactercontrollerissuelocalmotionglobal

Character Controller Not Moving Locally

I'm sorry if this has been asked before but I couldn't find anything on this

I made a simple capsule with Rigid Body physics, a Capsule Collider and a Character Controller (in that order). I created a basic c# script to control it and the script works fine but if i rotate the capsule, it keeps moving the same direction. Basically it's moving globally and not locally like i need it to. So yeah if someone can help me out with this that'd be great!

 public float mouseSensitivity = 5.0F;
 public float walkSpeed = 100.0F;
 
 private CharacterController controller;
 
 
 // Use this for initialization
 void Start () {
 
     controller = GetComponent<CharacterController>();
 
 }
 
 // Update is called once per frame
 void Update () {
     mouseLook ();
     processController ();
 }

 void mouseLook () {

     float h = mouseSensitivity * Input.GetAxis("Mouse X");
     transform.Rotate(0, h, 0);

 }
 
 void processController () {
 
     Vector3 v = new Vector3 (0, 0, 0);
 
     if (Input.GetKey ("w"))
         v.z += walkSpeed;
     if (Input.GetKey ("s"))
         v.z -= walkSpeed;
     if (Input.GetKey ("a"))
         v.x -= walkSpeed;
     if (Input.GetKey ("d"))
         v.x += walkSpeed;
 
     controller.SimpleMove (v * Time.deltaTime);
     
 }
Comment
Add comment · Show 8
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 getyour411 · Jan 25, 2014 at 08:10 PM 0
Share

On your rigidbody, do you have the flags checked for freeze rotations?

avatar image NunyoBusiness · Jan 26, 2014 at 01:16 AM 0
Share

Yes, I do. I've tried enabling and disabling them but still nothing.

avatar image Invertex · Jan 26, 2014 at 01:57 AM 0
Share

Use Vector3.forward to get the forward direction of an object, relative to it's rotation, and use that in your movement calculation. So if you rotated the character 90 degrees so it was facing downward, then Vector3.forward would point in a downward direction.

avatar image NunyoBusiness · Jan 26, 2014 at 02:10 AM 0
Share

I've already tried that. Still same thing...

avatar image getyour411 · Jan 26, 2014 at 02:24 AM 0
Share

you have walkSpeed as public, so the 100 set atop would be squashed by something in the Editor, you don't 0 in the Editor for walkSpeed?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Invertex · Jan 26, 2014 at 02:24 AM

You want transform.forward, not Vector3.forward. Vector3.forward will only give you worldspace forward. transform.forward will be local forward.

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

Classic Tetris like game - brick movement. 2 Answers

Rotating Player Controller locally or globally. 0 Answers

Move in global/world coordinate 1 Answer

rotate 90% in local space 4 Answers

Accessing variables from seperate scripts 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