Question by
seydlitz · Dec 10, 2019 at 04:03 PM ·
bug-perhapsproblema
Unity2D movement stutter in very simple scene
Hi!
I have a very simple scene with one character and fixed camera; the sprites stutter on movement!
Here is the movement script:
public class PlayerController : MonoBehaviour
{
public Vector2 MovementDirection;
Vector2 facing;
public float movSpeed;
public Rigidbody2D rb;
public Animator animator;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
ProcessInputs();
}
void FixedUpdate()
{
Move();
Animate();
}
void ProcessInputs()
{
if (MovementDirection.y == 0)
MovementDirection.x = Input.GetAxisRaw("Horizontal");
if (MovementDirection.x == 0)
MovementDirection.y = Input.GetAxisRaw("Vertical");
movSpeed = Mathf.Clamp(MovementDirection.magnitude, 0.0f, 1.0f);
MovementDirection.Normalize();
}
void Move()
{
//rb.velocity = MovementDirection * movSpeed;
rb.MovePosition(rb.position + MovementDirection * movSpeed * Time.deltaTime);
if (MovementDirection.x != 0 || MovementDirection.y != 0)
{
facing = MovementDirection;
}
}
void Animate()
{
animator.SetFloat("Horizontal", facing.x);
animator.SetFloat("Vertical", facing.y);
animator.SetFloat("Speed", movSpeed);
}
}
I have already tried the following:
switching between "Update" and "Fixed Update"
Playing with interpolate and the body type
Deleting every tile on the scene
Turning physics off (The character animate, doesn't move, and still stutter)
I really don't know what to do! Thank you!
Comment
Answer by seydlitz · Dec 11, 2019 at 04:09 PM
For anybody who has this problem: for me it was "GetAxisRaw". Try with GetAxis!