Quantcast
Channel: Questions in topic: "issue"
Viewing all articles
Browse latest Browse all 827

Issue with flipping an enemy when it reaches an edge

$
0
0
I'm using a linecast to detect whenever an enemy reaches an edge and then change its direction. When the enemy reaches an edge, it stops as it is supposed to, but it doesn't flip. Here is the relevant code: void Update () { transform.Translate (new Vector2 (_transform.localScale.x, 0) * moveSpeed * Time.smoothDeltaTime * stop); // enemy turns around when gets to an edge if (!Physics2D.Linecast (_transform.position, groundCheck.position, whatIsGround) && stop == 1) StartCoroutine (Flip ()); } IEnumerator Flip(){ stop = 0; yield return new WaitForSecondsRealtime (1); Vector3 localScale = _transform.localScale; localScale.x *= -1; _transform.localScale = localScale; stop = 1; }

Viewing all articles
Browse latest Browse all 827

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>