Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

enemy AI patrol not working

$
0
0
I made this code for my enemy but it just flickers side to side, anyone know what i could do ? using System.Collections; using System.Collections.Generic; using UnityEngine; public class MonsterAi : MonoBehaviour { public float speed; private bool movingRight = true; public Transform groundDetection; // Use this for initialization void Update() { transform.Translate(Vector2.right * speed * Time.deltaTime); RaycastHit2D groundinfo = Physics2D.Raycast(groundDetection.position, Vector2.down, 2f); 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; } } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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