• 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 itanium · Oct 25, 2012 at 04:21 PM · character controllermovedirection

Why sometimes movedirection.z doesn't work?

Hello, I have an object, to which is attached Character Controller and a script written by me. This object moves on 3 roads(on one road at a time), which are made from blocks(they are positioned tight together), and I can jump between them.

Problem is that there are situations, when I want to change the road(by pressing buttons left_p or right_p), but movedirection.z just doesn't work. I can see that the correct animation is playing, the height of the jump is jumpspeed/2 (the movement across y axis is working), but movedirection across z axis just doesn't happen. It happens not all the time, but sometimes. Can't explain when or why.

I tried to make three roads with three very long objects(not collection of many small blocks) and jump between them, and it works fine. Movedirection.z changes every time and the object simply jumps to other block.

Even tried to change collision box for these blocks, so these collision blocks overlapped, but it didn't help.

Does anyone have any ideas, how to solve this problem?

.... simplified code:

 public Vector3 moveDirection = Vector3.zero;

 void Awake()
 {
     controllers = GetComponent<CharacterController>();
     moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
     moveDirection = transform.TransformDirection(moveDirection);
     moveDirection *= speed; 
 }
 
 void Update()
 {
     moveDirection.x = speed;
     animation.CrossFade("run");
     
     if(controllers.isGrounded)
     {
 
         if(jump_p.GetComponent<buttons>().ispressed)
         {
             moveDirection.y = jumpSpeed;
             animation.Play ("jumpup", PlayMode.StopAll);
         }
         else if(left_p.GetComponent<buttons>().ispressed)
         {
             moveDirection.z = LRspeed;
             moveDirection.y = jumpSpeed/2;
             animation.Play ("left", PlayMode.StopAll);
         }
         else if(right_p.GetComponent<buttons>().ispressed)
         {
             moveDirection.z = -LRspeed;
             moveDirection.y = jumpSpeed/2;
             animation.Play ("right", PlayMode.StopAll);
         }
     }
 
 }
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 thedodgeruk · Nov 08, 2012 at 03:08 PM 0
Share

i not think any one can visualise this, can you make a video it, using fraps or some thing and post a link to it so can see what is going on

avatar image Seth-Bergman · Nov 08, 2012 at 03:23 PM 0
Share

what is "jump_p", "left_p", and "buttons"? The problem probably has to do with the logic behind "buttons.ispressed"

avatar image itanium · Nov 09, 2012 at 09:04 AM 0
Share

I doubt that there's something wrong behind buttons logic, because, when I replace many small blocks with 3 very LONG blocks and jump between them, everything works just fine. I can jump between these blocks hundred times If I want, every Jump happens.

Added picture for you : alt text

When this bug happens, I can see that my object jumps a little bit up and that animation "left/right" is playing and my object just falls down, because there's no block further.

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.

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

11 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

Related Questions

Moving along relative z axis with character controller? 1 Answer

how to make a first person character controller 1 Answer

Unity standard assets third person controller is auto crouching whenever there are objects above. How do I stop this? 2 Answers

How to get smooth 4 directional movement in top down without diagonal movement? 2 Answers

How to rotate a Character Controller on the X or Z axis ? (Not for movement) 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