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 Sunrift · Nov 06, 2011 at 10:44 AM · movementcollidercharactercontrollerjumpmove

controller.Move not working correctly

Hi, I am having a problem with moving a gameobject with a collider attached. I am using the collider.Move function: when I press "space" to jump, my character quits moving forward shortly after leaving the ground. If I increase my jump height, the character will move for part of the jump, but not all of it. The character always moves on the downward part of the jump and the first part of the upward part of the jump. Soon after leaving the ground, all movement on the x axis stops. I have done some logging, and the velocity.x remains a constant 1.5 this whole time. My character consists of a gameobject with a character controller, script, and animation attached. It also has a armature system attached as a child. I have completely disabled all animation, with no better results. I will attach my script as a reference.

 #pragma strict
 
 var playerMoveSpeed : float = 1.5;
 var jumpVelocity : float = 6.2;
 var gravity : float = 20.0;
 var moveDirection : int = 0;                        //reference for changing the direction the knight is facing
 var controller : CharacterController;
 
 
 private var velocity : Vector3;
 
 function Start ()
 {
     controller = GetComponent (CharacterController);
 }
 
 function Update ()
 {
     if (velocity.x > 0)                                //sets move direction
     {
         moveDirection = 0;
     }
     if (velocity.x < 0)                             //left
     {
         moveDirection = 1;
     }
     if (moveDirection == 0)                          //changes knight direction based on move direction, right
     
     {
         transform.localScale.z = 1;
         transform.eulerAngles = Vector3(0,180,0);
     }
     if (moveDirection == 1)                         //left
     {
         transform.localScale.z = -1;
         transform.eulerAngles = Vector3(0,0,0);
     }
     
     velocity.x = -1.5; //Input.GetAxis("Horizontal") * playerMoveSpeed;  I hardcoded the movement in to make sure I don't have an input issue.
     
     if (controller.isGrounded)                        //allows jumping while on ground.
     {
         if (Input.GetButtonDown ("Jump"))
         {
             velocity.y = jumpVelocity;
         }        
     }
     velocity.y -= gravity * Time.deltaTime;            //apply gravity
     controller.Move(velocity * Time.deltaTime);        //actually does the moving on character controller
     
     print (velocity.x);
     print (velocity.y);
     print (Time.deltaTime);
 }
Comment
Add comment · Show 3
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 Sunrift · Nov 06, 2011 at 08:02 AM 0
Share

Wow, I think I figured out how to fix this, although I really don't understand what is CAUSING the problem.

I had another gameobject as a child of my main character, and the child had a box collider attached. Enabling the trigger on the box collider solved the problem. Why this is, I have no idea, and if anyone could shed some light on that, I would much appreciate it. Thanks!

avatar image syclamoth · Nov 06, 2011 at 12:01 PM 0
Share

Well, you can make sure the two objects don't collide with each other, by putting them on different layers, then disabling collision between those layers. I actually have had a few problems like this, where objects would suddenly decide to accelerate into the air, never to be seen again, because of colliders interfering with each other!

avatar image Sunrift · Nov 06, 2011 at 06:44 PM 0
Share

Ok, If I come across a case where setting the collider to a trigger doesn't work, I will try the layer trick.

Um, noob question here, but how do I mark this question as answered?

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Two near-identical scripts cause a cat to jump in different ways - why? 2 Answers

How can I convert LOCAL transform.forward to WORLD Vector3? 2 Answers

Character Controller won't move forward 0 Answers

CharacterCollider.Move always goes up!?!?! 2 Answers

Natural Jump algorithm 2 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