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 Shin207 · Nov 11, 2021 at 09:49 AM · 3dcharactercontrollercharacter movement

My Jump Does not work,My Jump does not work

My character will not jump at all. I have tried many solutions but to no avail. (this is 3D) How to I fix this? I have tried using RigidBody gravity and the Rigidbody.AddForce but it does not work either.

 void Update()
 {
     Vector3 velocity = Vector3.zero;

     if (Input.GetKeyDown(KeyCode.Space))
     {
         Debug.Log("jumping");
         velocity.y = _jumpForce;
     }
     else 
     {
         // Apply gravity
         velocity.y -= _gravity;
     }
     

     

     // Move the controller
     _controller.Move(velocity * Time.deltaTime);
 }

This works for other people but not for me. I have an attached CharacterController. ,After trying many solutions, I am not able to make my character jump. I had simplified my code, and tried to debug the issue but to no avail. The script also logs "jumping", showing that it iterates through the section where the jump code is.

 // Update is called once per frame
 void Update()
 {
     Vector3 velocity = Vector3.zero;

     if (Input.GetKeyDown(KeyCode.Space))
     {
         Debug.Log("jumping");
         velocity.y = _jumpForce;
     }
     else 
     {
         // Apply gravity
         velocity.y -= _gravity;
     }
     

     

     // Move the controller
     _controller.Move(velocity * Time.deltaTime);

This is someone else's code that seems to work, but not for me. I tried using the RigidBody gravity system and using rb.AddForce but that doesnt work either. Even after removing the rigidbody component, I am still unable to jump. I have a CharacterController Attached.

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
Best Answer

Answer by Captain_Pineapple · Nov 11, 2021 at 10:02 AM

Hey there,

first up, Rigidbodys will not help if you are using a character controller.

The issue that you specifically face here is that your jump basically works - but it is so small and tiny that you cannot see it.


Why is that?

Becaus you set the velocity to something positive for 1 frame only. That beeing the frame in which you press space. The idea to then substract the gravity is alright but since you initialize the velocity vector to zero each frame you get a result like this over the frames:

velocity = -gravity

velocity = -gravity

velocity = -gravity

velocity = -gravity

velocity = jumpforce

velocity = -gravity

velocity = -gravity


so get rid of this your velocity variable should not be a local variable but a member of your class.

In addition you will have to check when you hit the ground. You should only ever accellerate downwards if you actually are in the air.

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

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

Related Questions

I cant move my character,My character wont move 0 Answers

Player Controller "Horizontal" input convert to "left" and "right" 1 Answer

How to replicate cylindrical collider boundries 0 Answers

Best way to control a Cube Like Character 0 Answers

Problems with the movement of custom character 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