- Home /
Question by
abdallah232 · Jun 22, 2020 at 07:45 AM ·
playerpatrolglitching
Enemy patrol is glitching
i wrote a script for my enemies in a game that im making to let them patrol(move back and forth) but every time that the enemy reaches the edge of the platform he starts glitching and doesn't know were to go. heres my script
{ public float speed;
public bool movingRight = true;
public Transform groundDetection;
public float distance;
void Update()
{
transform.Translate(Vector2.right * speed *Time.deltaTime);
RaycastHit2D groundInfo = Physics2D.Raycast(groundDetection.position, Vector2.down, distance);
if(groundInfo.collider == false){
if(movingRight == true){
transform.eulerAngles = new Vector3(0, -180, 0);
movingRight = false;
}
}
else{
transform.eulerAngles = new Vector3(0, 0, 0);
movingRight = true;
}
}
}
so what is the problem please help me. thanks
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613001515im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Character looks super jitery while moving? (2d) 1 Answer
glitching player 0 Answers
My player glitching on moving collider 0 Answers