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 /
  • Help Room /
avatar image
0
Question by Hiti3 · Sep 09, 2015 at 02:07 PM · movementvelocity2d-physicsfixedupdatejittering

How to fix minor jitter/stutter when moving a 2D character using physics in FixedUpdate()

Hey there, please help me out I'm searching the web for over a week to find a solution about why is my movement "jitterish" on a random intervals from 3-7 seconds I get 1 minor jitter.

PROBLEM: Receiving jitter on random times, 1 minor stutter/jitter per 3-5 seconds. Some say its not visible but it sure is, because I'm making an android game where your prediction of how much distance is to the next obstacle is really important. I'm amazed of how are other one tap/jump games made with 0 jitter.

I am receiving jitter in Editor and on standalone android apk.

I'm handling inputs in Update and moving in FixedUpdate. Camera follows in the LateUpdate.

What I have allready tried:

Update and LateUpdate methods:

  • transform.translate + Time.deltaTime (bad idea, i know)

  • rigidbody2d.velocity + Time.deltaTime (still bad idea)

FixedUpdate method (Timestep: 0.01333 / 75 fps):

  • rigidbody2D.AddForce

  • rigidbody2D.velocity + Interpolation/Extrapolation (my current one)

Nonetheless which option I choose it still jitters.

Working example in Unity WebPlayer

Here is the code:

In the first class I have my camera follow the player. And in the second one there is player movement and other controlls.

Camera script:

 using UnityEngine;
 using System.Collections;
 
 public class CameraScript : MonoBehaviour {
 
     public Transform player;
     public Vector3 offset;
 
     private Vector3 targetPos;
     
     void LateUpdate () 
     {  
         // Smooth follow of the camera
         targetPos = new Vector3(player.position.x + offset.x, transform.position.y, transform.position.z);
         transform.position = Vector3.Lerp(transform.position, targetPos, 6.0f * Time.deltaTime);
     }
 }
 

Movement script:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     
     public float moveSpeed = 0;
     public float jumpHeight = 0;
     public Rigidbody2D playerRigidbody;
     public Transform playerTransform;
 
     public Animator anim;
     
     private bool grounded = false;
     private bool jump = false;
     private Transform groundCheck;
 
     private Vector3 start;
     
     void Awake () 
     {
         // Find the groundCheck child transform
         groundCheck = transform.Find ("groundCheck");
     }
 
     void FixedUpdate()
     {
         // Move the player using physics
         playerRigidbody.velocity = new Vector2(moveSpeed, playerRigidbody.velocity.y);
         
         if (jump) {
             playerRigidbody.velocity = new Vector2(playerRigidbody.velocity.x, jumpHeight);
             jump = false;
         }
     }
 
     void Update ()
     {
     
         // Cast a line to the ground so we cant jump while in mid-air
         grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
 
         #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
                 
             if(Input.GetKeyDown(KeyCode.UpArrow) && grounded) {
                 jump = true;
             }
                 
         #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
                 
             if(Input.touchCount > 0){
                 Touch[] myTouches = Input.touches;
                 
                 // Handling multi-touch input
                 for(int i = 0; i < Input.touchCount; i++){
                     Touch myTouch = Input.GetTouch(i);
                     
                     if(grounded && myTouch.phase == TouchPhase.Began) {
                         jump = true;
                     }
                 }
             }
         #endif
     }
 }


Comment
Add comment · Show 2
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 Hiti3 · Sep 09, 2015 at 01:36 PM 0
Share

Anyone? please . . .

avatar image Hiti3 · Sep 10, 2015 at 08:33 AM 0
Share

Really no one to help?

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D Velocity movement on slope hops when moving left/right 0 Answers

How do I assign a velocity to an object on only 1 axis? 1 Answer

Using rb.velocity and Add Force on the same gameobject? 0 Answers

Counteracting rigidbody velocity using AddForce? 0 Answers

my box movements look jitter, how to fix it 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