- Home /
Question by
$$anonymous$$ · Apr 21, 2018 at 07:09 PM ·
2d gamemovement scriptnpcjittering
Jittery NPC movement?
Hello, I've made a method for moving my NPC to a destination, but for some reason it has the jitters even though I'm running the method in FixedUpdate.
public void Move(Vector2 MoveTo){
if (transform.position.x > SeekPosition.x) {
transform.Translate (new Vector2 (-1 * Speed * Random.Range(-0.1f, 0.01f), 0));
} else {
transform.Translate (new Vector2 (1 * Speed * Random.Range(-0.1f, 0.01f), 0));
}
if (transform.position.y > SeekPosition.y) {
transform.Translate (new Vector2 (0, -1 * Speed * Random.Range(-0.1f, 0.01f)));
} else {
transform.Translate (new Vector2(0, 1 * Speed * Random.Range(-0.1f, 0.01f)));
}
}
Comment
Best Answer
Answer by $$anonymous$$ · Apr 21, 2018 at 10:54 PM
I started using transform.position += rather than Translate and that seems to have fixed the issue.
public void Move(Vector2 MoveTo){
transform.right = new Vector2(transform.position.x, transform.position.y) - SeekPosition;
transform.position += -transform.right.normalized * Speed;
}
Answer by CranberryHorses · Apr 21, 2018 at 07:59 PM
Maybe you could try replacing Random.Range with Time.DeltaTime