- Home /
Question by
kingdomkind · Feb 23 at 07:48 PM ·
2dscripting problemspriterigidbody2dtopdown
2D character movement is jittery (top-down)
Hello! I'm having an issue where my character "jitters"
Here's a video on it: https://streamable.com/fqn611
Here's the code for that specific part:
Movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
Rigid_body.MovePosition((Vector2)transform.position + (Movement * Walk_Speed * Time.deltaTime));
It runs on fixed update:
void FixedUpdate() {
Controller.Move(Walk_Speed);
}
Here's the entire character code, incase it's needed:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character_Controller : MonoBehaviour
{
private Animator Animator_Parameters;
private SpriteRenderer Sprite_Renderer;
private Rigidbody2D Rigid_body;
void Start() {
Animator_Parameters = GetComponent<Animator>();
Sprite_Renderer = GetComponent<SpriteRenderer>();
Rigid_body = GetComponent<Rigidbody2D>();
}
public void Move(float Walk_Speed) {
if (Input.GetAxisRaw("Horizontal") == 1) {
Sprite_Renderer.flipX = false;
} else if (Input.GetAxisRaw("Horizontal") == -1) {
Sprite_Renderer.flipX = true;
}
Vector2 Movement;
/*
if (Input.GetAxis("Vertical") != 0) {
Movement = new Vector2(0, Input.GetAxis("Vertical"));
//transform.Translate(Movement * Walk_Speed * Time.deltaTime);
//Rigid_body.AddForce(Movement * Walk_Speed * Time.deltaTime);
Rigid_body.MovePosition((Vector2)transform.position + (Movement * Walk_Speed * Time.deltaTime));
Animator_Parameters.SetBool("Moving", true);
}
if (Input.GetAxis("Horizontal") != 0) {
Movement = new Vector2(Input.GetAxis("Horizontal"), 0);
//transform.Translate(Movement * Walk_Speed * Time.deltaTime);
//Rigid_body.AddForce(Movement * Walk_Speed * Time.deltaTime);
Rigid_body.MovePosition((Vector2)transform.position + (Movement * Walk_Speed * Time.deltaTime));
Animator_Parameters.SetBool("Moving", true);
}
*/
//var moveVector = new Vector3(Input.GetAxis("Horizontal") , Input.GetAxis("Vertical") , 0);
//Rigid_body.MovePosition(new Vector2((transform.position.x + moveVector.x * Walk_Speed * Time.deltaTime),
// transform.position.y + moveVector.y * Walk_Speed * Time.deltaTime));
if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) {
Animator_Parameters.SetBool("Moving", true);
}
Movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
Rigid_body.MovePosition((Vector2)transform.position + (Movement * Walk_Speed * Time.deltaTime));
if (Input.GetAxis("Vertical") == 0 && Input.GetAxis("Horizontal") == 0) {
Animator_Parameters.SetBool("Moving", false);
}
}
}
(Quite alot is commented out)
If you need any information, please don't hesitate to ask! Thank you!
Comment
Answer by Spip5 · Feb 23 at 11:21 PM
It is likely related to your camera script instead of you character controller. Is your camera code running in the update or LateUpdate method ? Try both (and FixedUpdate), see if there is any change !