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 kole_dole · Mar 26, 2020 at 10:11 PM · movementrigidbody2dplatformer

2d platformer player jitter when add velocity

Hi,

I'm trying to make platformer player that moving forward and backward.

Player is simple sprite

Here is my code:

     private void FixedUpdate()
     {
          moveInput = Input.GetAxisRaw("Horizontal");
          rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
 }

But when I try to move player I feel jitter (player not smooth moving) . Can problem be some settings in unity or problem is in code ?

When I use follow player script player moves smooth but then camera jitter (not moving smooth) Here is my folow camera code:

         void FixedUpdate()
         {
             Vector3 playerPos = player.position;
             playerPos.z = transform.position.z;
             transform.position = Vector3.SmoothDamp(transform.position, playerPos, ref velocity, smoothTime);
             transform.position = new Vector3(Mathf.Clamp(transform.position.x, minCameraPos.x, maxCameraPos.x),Mathf.Clamp(transform.position.y, minCameraPos.y, maxCameraPos.y),
 Mathf.Clamp(transform.position.z, minCameraPos.z, maxCameraPos.z));
         }

Please help me. Thanks!

alt text

untitled.png (29.7 kB)
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 Jacobsc · Mar 26, 2020 at 10:13 PM 0
Share

I think you're missing delta time in your movement, that could be the reason.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kubajs · Mar 26, 2020 at 10:29 PM

Feel free to set rigidbody.velocity in Update method. Do a camera follow in LateUpdate. Everything will be smooth as expected. Also test that in built mode, not regular play mode as you won't usually eliminate jittering completely in play mode. Just CTRL + B and run in full screen. No need to set rigidbody.velocity in FixedUpdate as velocity can be set at any time, doesn't matter whether it's set in fixed intervals or not. Your problem is caused purely by the camera follow script. FixedUpdate method is not appropriate for this. When modifying camera transform, just run it in LateUpdate as LateUpdate always execute after Update. Move other than camera transforms in Update. Also always try to read user input in Update instead of FixedUpdate. In your case it's not a big issue but in case you read GetButtonDown (one time input), you'll realize it sometimes doesn't work (in the case input was read in the frame which was skipped by fixed update).

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 kole_dole · Mar 27, 2020 at 08:53 PM 0
Share

Thanks, I try everything but I still have jitter . I think problem might me in Unity or project settings,

avatar image kubajs kole_dole · Mar 29, 2020 at 03:26 PM 0
Share

Try to play with Rigidbody2D interpolation, it might improve it a bit.

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

189 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

Related Questions

I want to move the player once while he is jumping 1 Answer

Character dragging ground with it. 1 Answer

Rigidbody2D character movement problem 0 Answers

Rigidbody2D jumping off of slopes 0 Answers

How to Move Platform up and down even if player stands on it. 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