- Home /
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);
}
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?
Okay So I tried Time.Deltatime and no difference.... and I checked and no Im not using LateUpdate for the camera. Should I?
Answer by exzizt · Mar 24, 2018 at 10:51 PM
Trying user interpolation/extrapolation on your rigidbody.
Your answer
![](https://koobas.hobune.stream/wayback/20220612155242im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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