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
1
Question by Freddie · Feb 11, 2011 at 07:24 PM · charactercontrollerjitter

Character Controller Jittering Problem

hey, i'm having some problems using the character controller, i've checked all over the web but i can't find any reason for it jittering.

this is my code:

var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate //move direction directly from axes if((Input.GetAxis("Horizontal") < -0.1) || (Input.GetAxis("Horizontal") > 0.1)){ moveDirection = Vector3(0, 0, 1 * speed); } else { moveDirection = Vector3(0, 0, 0); } moveDirection = transform.TransformDirection(moveDirection);

 if (Input.GetKey ("w")) {
     moveDirection.y = jumpSpeed;
 }

} else { // Apply gravity moveDirection.y -= gravity * Time.deltaTime; }

// Move the controller controller.Move(moveDirection * Time.deltaTime);

//KEEP IT IN LINE YOU SLAG! transform.position.x = depth;

and it's all housed in a 'FixedUpdate()' function

any ideas? thanks in advance

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jessy · Feb 11, 2011 at 09:39 PM

You have to apply "gravity" every frame, otherwise it pops out of the ground continuously. I remember providing some code to fix this at some point, on the forum, but the basic idea is that you just set moveDirection.y to the smallest negative value you can, every frame you're grounded, that fixes the issue. That way, when you walk off an edge, you aren't falling really fast immediately, which would happen if you just took

moveDirection.y -= gravity * Time.deltaTime;

out of the else statement.

And no, the scripting example has never accounted for falling off an edge properly.

Edit: Here is that forum post.

Comment
Add comment · Show 2 · 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 Freddie · Mar 09, 2011 at 09:58 PM 0
Share

i am applying gravity each frame, i already had the code you gave in the script. the problem isn't vertical jitter it's that the controller seems to lag even though unity is running at 600fps. thanks though.

avatar image Jessy · Mar 10, 2011 at 04:16 AM 0
Share

No you're not. You're only applying gravity if you're not grounded. As I detailed, that doesn't work.

avatar image
1

Answer by starkos · Apr 17, 2011 at 06:19 PM

It sounds like an issue with using FixedUpdate/Update/LateUpdate. If you move your character in FixedUpdate, and move your camera in Update, you'll get quite severe jitter. Seeing as there is nothing in your code above that really requires a fixed timestep, try moving it into Update and see if that helps.

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

No one has followed this question yet.

Related Questions

Ball Character controlled by a single Joystick? 0 Answers

Character Controller Script 3 Answers

character controller quit working, script errors 0 Answers

Object reference not set to instance of an object 2 Answers

Camera shake 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