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 ragefordragons · Mar 24, 2018 at 03:23 AM · movementplayerfixedupdateglitching

Character looks super jitery while moving? (2d)

So I have been using transform.translate for my character controller (which is bad I know) and so I am attempting to switch it to rigidbody 2d.velocity right? However, whenever I do that there is some glitch where when I walk it looks like i teleport back slightly every frame.... I have tried a lot of things, like multiplying it by time.fixeddeltatime and such... nothing seems to fix it. What am I doing wrong??

public class playerController : MonoBehaviour {

 //MOVEMENT
 [Tooltip("The maximum horizontal movement speed in units per second.")]
 public float speed = 8; // movenment speed for Luca

 [Tooltip("The maximum vertical jump speed in units per second.")]
 public float jumpspd = 12; // jumo height for Luca

 private float moveInput;
 private Rigidbody2D rb;

 
 public Transform groundCheck;
 public float checkRadius;
 public LayerMask whatIsGround;

 //ANIMATION
 public Animator anim;
 bool canDash = true;
 private bool grounded;
 bool isRunning;
 public SpriteRenderer ren;

 //UNUSED AS OF NOW
 public static float LucaHP;
 public static float LucaSP;
   

 //TODO: MOVE ONTO NEW SCRIPT
   




 // Use this for initialization
 void Start()
 {

     anim = gameObject.GetComponent<Animator>();
     anim.SetBool("isRunning", false);
     anim.SetBool("dashing", false);
     anim.SetBool("isJumping", false);
    

     canDash = true;

     rb = GetComponent<Rigidbody2D>();
 }

 // Update is called once per frame

 void Update()
 {
     HandleDash();
     HandleFlip();
     HandleJump();
     anim.SetBool("isRunning", isRunning);
     if (Input.GetButton("Horizontal"))
     {
         isRunning = true;

     }
     else
     {
         isRunning = false;
     }
     

     if (grounded == true)
     {
         anim.SetBool("isJumping", false);
     }
     
 }

 void FixedUpdate()
 {
     playermove();
     
 }






 void playermove()
 {
     grounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);


    
     float axixX = Input.GetAxis("Horizontal");
     //transform.Translate(new Vector2(axixX, 0) * Time.deltaTime * speed);

     rb.velocity = new Vector2(axixX * speed * Time.fixedUnscaledDeltaTime, rb.velocity.y);

     
 }
Comment
Add comment · Show 3
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 hexagonius · Mar 24, 2018 at 06:28 AM 0
Share

You can use regular deltatime, which internally is fixeddeltatime when called in fixed update. your code for movement looks right.
is your camera following in LateUpdate?

avatar image ragefordragons hexagonius · Mar 24, 2018 at 02:50 PM 0
Share

Okay So I tried Time.Deltatime and no difference.... and I checked and no Im not using LateUpdate for the camera. Should I?

avatar image hexagonius ragefordragons · Mar 24, 2018 at 08:45 PM 0
Share

well, yes you should

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by exzizt · Mar 24, 2018 at 10:51 PM

Trying user interpolation/extrapolation on your rigidbody.

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

126 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

Related Questions

glitching player 0 Answers

Player movement for iOS? 1 Answer

2.5D Isometric Move Character and Facing towards mouse 0 Answers

How can i smooth out the rotation? 1 Answer

Player move along fixed line with inputs of keybord keys for increasing and decreasing the speed and up and down for take turn! 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