Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by murkantilism · Sep 12, 2015 at 05:19 AM · charactercontrollerjumpingmovingrunauto

CharacterController - moving while jumping (movement vector values reset?)

I have an autorunner movement script - I'm trying to get jumping while moving working with a CharacterController.

I'm seeing this odd behavior: when I jump, the X and Z members of the movementVector in the player script are reset to 0, even though I'm only setting the .y member to jumpSpeed. This means that when I jump, I stop moving and only go up in the Y direction for a bit then continue autorunning.

I found this thread that suggested I separate the vertical speed into another variable, so here's that version of the movement script. The previous version just set movementVector.y = jumpSpeed directly when the Jump Input was pressed. Both versions result in the same behavior (stopping movement until jumping is over).

 void FixedUpdate() {
     if (controller.isGrounded) {
         // Set movement vector to forward transform
         movementVector = transform.forward;

         // Apply player's speed
         movementVector *= _movementProperties.playerSpeed;

         // A grounded character has 0 vertical speed unless...
         _movementProperties.vertSpeed = 0.0f;
         // jump input is pressed
         if (Input.GetButton("Jump")){
             _movementProperties.vertSpeed = _movementProperties.jumpSpeed;
         }else{
             _playerProperties.jummping = false;
         }

     }else{
         // REMOVED - There's a LOT of code here for when we aren't grounded, not relevant 
         }
     }
     
     // Apply gravity to vertical speed
     _movementProperties.vertSpeed -= _movementProperties.gravity * Time.deltaTime;
     // Assign vertical speed to movement vector
     movementVector.y = _movementProperties.vertSpeed;
     // Apply final movement vector
     if (_playerProperties.aliveP){
         controller.Move(movementVector * Time.deltaTime);
     }
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by EssyTech · Sep 12, 2015 at 07:12 AM

Input.GetButton will only execute the code inside of its block if the button is held down. Are you just tapping the button or holding the button? Also, you should run your input commands in update not fixed update because update gets run every frame were fixed update does not.

Comment
Add comment · Show 4 · 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 murkantilism · Sep 12, 2015 at 04:21 PM 0
Share

Originally I had GetButtonDown but I changed it to GetButton so I could hold the input and see what was going on with the jumping.

The movementVector's x and z are still unexplainedly modified when it's GetButtonDown, the visual effect of interrupting movement is just less noticeable (still there).

$$anonymous$$oving the jumping input to Update() doesn't address the actual problem, neither of the issues you discussed do.

avatar image EssyTech · Sep 13, 2015 at 12:49 AM 1
Share

The comment you put were is said the the code for not being grounded is not relevent could be were the issue lies. If the player is not grounded, hence they are jumping, (isGrounded is probably false) then the code that you put in the not grounded section will be executing. Need to look there. Since its not present here, I don't no how else to help.

avatar image murkantilism EssyTech · Sep 13, 2015 at 01:06 AM 0
Share

Thanks for the replies I actually fixed this earlier today, you are correct the Else of the isGrounded check was one part of movementVector being messed with.

avatar image EssyTech murkantilism · Sep 13, 2015 at 05:39 AM 0
Share

Glad you fixed it :)

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I can't do that my character jumps while running 0 Answers

Moving player while jumping 1 Answer

attached.Rigidbody isn't working with a ChactacterController? -1 Answers

Why can't I properly jump? 2 Answers

Collision of a moving object with a standard 3rd person controller 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