Quantcast
Channel: Questions in topic: "merge"
Viewing all articles
Browse latest Browse all 202

My enemies merge when they come towards me

$
0
0
public Transform target; public int moveSpeed; public int rotationSpeed; public int maxDistance; private Transform myTransform; // Use this for initialization void Start () { GameObject go = GameObject.FindGameObjectWithTag("Player"); target = go.transform; } void Awake () { myTransform = transform; } // Update is called once per frame void Update () { float distance = Vector3.Distance(target.transform.position, transform.position); myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position),rotationSpeed * Time.deltaTime); if(distance < 15f && Vector3.Distance(target.position, myTransform.position) > maxDistance) { myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime; } } this is the code I have On my enemy the allows them to come towards me, but when multiple enemies is coming towards me the just merge into one, any suggestions on how I can fix this. "Comment" if the code looks messy I can re-post it :)

Viewing all articles
Browse latest Browse all 202

Trending Articles



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