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

Enemy 2D check for collision

$
0
0
Currently i have a basic enemy follow script but he gets caught on walls and such in my 2D topdown game and i wanted to make him check for collision but im not exactly sure how to do this here is my public class EnemyFollow : MonoBehaviour { public float speed; private Transform target; private void OnTriggerStay2D(Collider2D collision) { { if (Vector2.Distance(transform.position, target.position) > 1.0) { transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime); } } } // Use this for initialization void Start() { target = GameObject.FindGameObjectWithTag("Player").GetComponent(); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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