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 LunaArgenteus · Sep 16, 2012 at 09:26 PM · collisionmovementcharactercontroller

CharacterController.Move() is causing unwanted vertical movement . . . how to fix?

Alright, so the Move() function of the character controller has me stumped. I have a little capsule in my scene and I just wanted to get it moving around, so I wrote the code below. Here's the thing - when I press any two directions (up and right, left and up, etc), the Move() function of the CharacterController starts changing the y values of the character's position. I cannot for the life of me figure out why this is happening. Using transform.position += does not yield the same problem. Any help would be MUCH appreciated.

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(CharacterController))]
 public class DummyPlayer : MonoBehaviour {
     
     protected CharacterController myCharacterController;
     
     void Start () {
         myCharacterController = this.GetComponent<CharacterController>();
     }
     
     void Update () {
         ProcessInput();
     }
     
     private void ProcessInput() 
     {
         float analogZ = Input.GetAxis("Vertical");
         float analogX = Input.GetAxis("Horizontal");
         
         Vector3 moveVect = new Vector3(analogX, 0, analogZ); 
         
         if(moveVect.y != 0 || this.transform.forward.y != 0)
         {
             Debug.Log(moveVect.y + " " + this.transform.forward.y); //never called
         }
         
         //this.transform.position += moveVect*Time.deltaTime*40f;
         myCharacterController.Move(moveVect*Time.deltaTime*40f); //why does this affect my y value when the line commented out above doesn't?
         
     }
 }

Also, the variables are named analogX and analogZ because eventually I'd like to get input from a joystick - for now I'm just using the keyboard.

UPDATE:

So after some experimenting around with project settings, I added the following lines to the end of my ProcessInput() function:

 if(myCharacterController.collisionFlags != CollisionFlags.None)
 {
     Debug.Log("I understand nothing anymore.");
 }

then ran the program. When I perform the steps necessary to recreate my original problem, every few updates, I see the Debug statement in the console. Mind you, that aside from the default camera Unity adds when you start a project, I have nothing in the scene except for my childless, parentless capsule. I cannot fathom how it is colliding with itself. Please help!

Comment
Add comment · Show 7
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 justinl · Sep 17, 2012 at 04:54 AM 0
Share

What does it say when you check the `myCharacterCtonroller.velocity`? Something to do with gravity came to $$anonymous$$d as the CharacterController doesn't apply gravity automatically (http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.$$anonymous$$ove.html)

avatar image LunaArgenteus · Sep 17, 2012 at 07:17 AM 0
Share

justinl - Well, I think that's a start in the right direction - I just checked myCharacterController.velocity and when I hold down "right" and "up," every 3 or 4 updates (not consistent) it has a non-zero y component (which is anywhere between 8.6 or so to about 17.7).

However, I still have absolutely NO idea why it's happening, as I too was under the impression that the $$anonymous$$ove() function of CharacterController applied no gravity. Even so, the y component is always positive. Hmm . . .

avatar image justinl · Sep 17, 2012 at 07:29 AM 0
Share

Yeah I'm not really sure what's going on either but I'm curious to find out the reason. Is the terrain completely flat?

avatar image LunaArgenteus · Sep 17, 2012 at 07:35 AM 0
Share

Well, right now, I don't have any terrain and am just moving my capsule in free space. Earlier though, I was curious about whether the IsGrounded property had anything to do with it so I created a flat terrain and applied a small constant downwards velocity to my capsule - when I would move I'd stop being grounded and start to fly.

But again, right now the capsule is the only object in the scene (not including the default camera).

avatar image justinl · Sep 17, 2012 at 08:08 AM 0
Share

So if I wanted to re-create your scene, all I would have to do is start a new project, create a capsule, apply the character controller component onto it, and then the script you've copied and pasted above?

Show more comments

2 Replies

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

Answer by LunaArgenteus · Sep 18, 2012 at 03:35 AM

Hahaha, alright people, I found the answer - ready for the face-palm moment? The capsule WAS colliding with itself - I had forgotten that CharacterController creates its own collider, and thus forgot to remove the default collider that is attached when one creates a game object. Everything is working now - thanks to both the people who tried helping me before I figured it out!

The lesson of the story for those who have similar problems with a CharacterController - first check to see if your character has any other colliders on it.

Comment
Add comment · Show 3 · 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 justinl · Sep 18, 2012 at 06:25 AM 0
Share

haha. Thanks for posting back ::face palm::

avatar image RFLG · Apr 25, 2014 at 10:31 PM 0
Share

Good call, just found myself doing the same mistake, your thread was a time-saver! ...face-palms self with a frying pan...

avatar image cjke-7777 · May 08, 2014 at 11:40 AM 0
Share

Thank you! Thank you! This killed me for 24 hrs!!

avatar image
0

Answer by Seth-Bergman · Sep 17, 2012 at 08:24 AM

maybe add the line:

 Vector3 moveVect = new Vector3(analogX, 0, analogZ); // after this
 moveVect = transform.TransformDirection(moveVect); // add this line
 ...etc

http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.Move.html

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 LunaArgenteus · Sep 17, 2012 at 08:52 AM 0
Share

Nope, not working.

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

14 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

Related Questions

How can I guarantee a CharacterController never leaves the ground? 2 Answers

Stop animation when character controller hits walls 1 Answer

Why does my character fly upwards when I click play? 1 Answer

How to hold objects in third person? 1 Answer

issue applying vector for slope sliding 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