- Home /
(NEW USER) 2D character movement is laggy
I used this script I got from a video:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour { public float speed; private Rigidbody2D myRigidbody; private Vector3 change; // Start is called before the first frame update void Start() { myRigidbody = GetComponent();
}
// Update is called once per frame
void Update()
{
change = Vector3.zero;
change.x = Input.GetAxisRaw("Horizontal");
change.y = Input.GetAxisRaw("Vertical");
if (change != Vector3.zero)
{
MoveCharacter();
}
}
void MoveCharacter()
{
myRigidbody.MovePosition(
transform.position + change * speed * Time.deltaTime
);
}
}
This is the video: https://www.youtube.com/watch?v=--N5IgSUQWI&list=PL4vbr3u7UKWp0iM1WIfRjCDTI03u43Zfu∈dex=3
And it works other than movement randomly stuttering. I am using version 2019.420f1 and the guys version in the video is older so maybe its that? I'm super new to this...
Comment