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 davidjusa · Feb 11, 2021 at 10:07 PM · 2d2d-physics2d sprites

Rigidbody2D interpolate setting lets player fly

Hey guys. Yesterday i made a thread where i asked how i could fix the problem with my jittering. I saw many answers on other threads that you should turn on the interpolate setting. Well for me the interpolate setting does this (video attached) link text This is my movementScript:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerMovement : MonoBehaviour
 {
     public float movementSpeed = 1;
     public float JumpForce = 1;
 
     private Rigidbody2D _rigidbody;
     // Start is called before the first frame update
     private void Start()
     {
         _rigidbody = GetComponent < Rigidbody2D >();
     }
 
     // Update is called once per frame
     private void Update()
     {
         var movement = Input.GetAxis("Horizontal");
         transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * movementSpeed;
 
         if(Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f){
             _rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
         }
     }
 
   
 
 }


 

And this is my CameraFollowScript (you probably wont need that):

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraFollow : MonoBehaviour
 {
     public Transform target;
     public Vector3 offset;
     public float smoothFactor;
 
 
     private void FixedUpdate()
     {
         Follow();
 
     }
 
     void Follow()
     {
         Vector3 targetPosition = target.position + offset;
         Vector3 smoothPosition = Vector3.Lerp(transform.position, targetPosition, smoothFactor * Time.fixedDeltaTime);
         transform.position = smoothPosition;
     }
 
 }

I want to turn on the interpolate setting because this could maybe stop the jittering but as you see in the video it does some weird stuff which is probably related to the movementScript but im still a total beginner and noob thats why i cant see where the problem in the coding is. If someone knows a solution which solves this problem please help me :( (also if you know a solution for the jittering problem in general you are more than welcome to write it in the thread :) )

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

Answer by Box_Frog · Feb 12, 2021 at 12:52 AM

I had a similar problem before and the issue was the camera. If you disable the camera script is your player still jittery? I was playing around with your camera script, try to multiply your smoothFactor by Time.deltaTime instead of fixedDeltaTime.

 public class CameraFollow : MonoBehaviour
     {
         public Transform target;
         public Vector3 offset;
         public float smoothFactor;
 
         private void Start()
         {
             offset = transform.position - target.position;
         }
 
         private void FixedUpdate()
         {
             Follow();
 
         }
 
         void Follow()
         {
             Vector3 targetPosition = target.position + offset;
             Vector3 smoothPosition = Vector3.Lerp(transform.position, targetPosition, smoothFactor * Time.deltaTime);
             transform.position = smoothPosition;
         }

Comment
Add comment · Show 6 · 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 Box_Frog · Feb 12, 2021 at 01:02 AM 0
Share

also in unity if you go to "Window" then "Package manager" there's a really useful package called Cinemachine. Here's a tutorial if you're interested. Tutorial Link

avatar image davidjusa · Feb 12, 2021 at 07:22 AM 0
Share

$$anonymous$$y player is still jittering even with Time.deltaTime. And no, my player isnt jittering anymore when i turn off the camera script. I also tried cinemachine, but my player still jittered lol. Imma try changing the sprite maybe that will help?

avatar image Box_Frog davidjusa · Feb 12, 2021 at 08:22 AM 0
Share

What do you have your offset or smoothFactor set to? And I forgot to mention that with Cinemachine under your main camera in the CinemachineBrain I change the "Update $$anonymous$$ethod" and "Blend Update $$anonymous$$ethod" to Fixed Update.

avatar image davidjusa · Feb 12, 2021 at 08:53 AM 0
Share

$$anonymous$$y offset setting is set to -1 and my smooth factor is set to 3. With cinemachine my character only jitters when jumping. When i do fixedUpdate on both it jitters in all ways again. When i do smart update on Update$$anonymous$$ethod and LateUpdate on BlendUpdate$$anonymous$$ethod its the best so far, because my player is only a bit jittery when in air.

avatar image Box_Frog davidjusa · Feb 12, 2021 at 09:31 AM 0
Share

Hmm. you could try and put your player movement ( transform.position += new Vector3(movement, 0, 0) Time.deltaTime movementSpeed; ) in FixedUpdate and then Cinemachine to Update in FixedUpdate.

avatar image davidjusa Box_Frog · Feb 12, 2021 at 02:04 PM 0
Share

Dude that fixed it. I put my movement in FixedUpdate and for my jump if statement i made a new script (becuase jumping in FixedUpdate doesnt really work). All jitteriness is gone. Thx a lot!

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

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

how to make a 2d character three-dimensional? 1 Answer

Help Me! I want to make a pixel fairy! 1 Answer

Push 2d Player Object in Opposite Direction of Collision,Push Player 2d Object in Opposite Direction of Collision 0 Answers

2D Dust Particle Trail? 1 Answer

How do I stop my sprite from jumping in the air? 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