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
0
Question by luc4m4rio · Jul 02, 2018 at 05:50 PM · unity 52dcharacter controllercustomdevelopment

My character controller is quite unresponsive, help pls

I recently got into Unity and I'm making my own controller for my 2D game, it works alright but the jump is very unresponsive. Like, it maybe jumps 5 out of 10 times when pressing the space button and I have no idea why. I'm using the built in Character Controller and the IsGrounded check. Any help is appreciated, thanks!

[RequireComponent(typeof(CharacterController))] public class PlayerController : MonoBehaviour {

 private CharacterController controller;

 private int speed = 12;

 private Vector2 moveVector;
 private float verticalVelocity;
 private float gravity = 1;

 public Transform jumpPos;

 private void Start ()
 {
     controller = GetComponent<CharacterController>();
 }
 
 private void Update ()
 {
     Movement();
 }

 private void Movement()
 {
     float inputDirection = Input.GetAxis("Horizontal") * speed;
     if (controller.isGrounded)
     {
         verticalVelocity = 0;
         if (Input.GetKeyDown(KeyCode.Space))
         {
             controller.transform.position = jumpPos.transform.position;
         }
     }
     else
     {
         verticalVelocity -= gravity;
     }
     moveVector = new Vector2(inputDirection, verticalVelocity);
     controller.Move(moveVector * Time.deltaTime);
 }
Comment
Add comment · Show 1
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 TreyH · Jul 02, 2018 at 07:02 PM 0
Share

Without knowing what CharacterController is, we can't really do much here. Since its .isGrounded flag is the only thing of note here, are you sure the block within that if statement is executing each time you expect the character to be "grounded"?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Epicepicness · Jul 02, 2018 at 08:16 PM

I've had similar issues with Unity's build-in Character Controller (eventually leading to me making a custom one instead). The reason it's unresponsive is because the CharacterController.isGrounded isn't reliable and flips between true/false practically every frame. This means that it'll only jump if it's true on the exact frame you push the jump key. While I'm not entirely sure why this happens, it seems to be a result from Unity's collider 'pushing' you up as to not be stuck in the surface.

So I don't have an exact answer for you, but after some googling you could try to following:

  • you can try making the jump input a GetKey, rather than a GetKeyDown. This would mean the jump is sometimes one frame late, however.

  • Replace "verticalVelocity = 0;" with "verticalVelocity = -gravity * Time.deltaTime;"

  • Call the Controller.Move() function twice (first use seems to fix, second to actually move). Not optimal. by this logic you could apply the Move() before checking the grounded, and if you should jump or not?

I think the second option is the best one to try first, and see if it solves anything. Hope this was helpful. :)

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

254 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 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

Help with pixel perfect, thanks. 2 Answers

[2D] How to instantiate laser when player rotates? 1 Answer

Why is the Enemy's Sprite Flipping When it Sees the Player?? 0 Answers

How can I remove inertia from character controller? 0 Answers

Animation is not playing all frames 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