Question by
lawrence89 · Sep 27, 2016 at 06:26 AM ·
c#unity 5
Unity 3D: C# NPC Colliding each other
Hey guys, new to C# and Unity
I know how to stop my NPC's colliding into the player, i just can't seem to figure out how i can get them to stop colliding into each other as well as the player?
The NPC's have a tag of "AI", i have tried a few things now but i really can't figure this out?
Here is my code, any help is appreciated :) thanks guy
using UnityEngine;
using System.Collections;
public class AI : MonoBehaviour {
public Transform target;
public int moveSpeed = 5;
public int rotationSpeed = 2;
public Transform myTransform;
public float minDistance = 0.1f;
void Awake ()
{
myTransform = transform;
}
void Start ()
{
target = GameObject.FindWithTag ("Player").transform;
}
void Update ()
{
Vector3 Distance = target.position - myTransform.position;
if(Distance.sqrMagnitude>minDistance*minDistance)
{
myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation (target.position - myTransform.position), rotationSpeed * moveSpeed * Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
Comment
Your answer
Follow this Question
Related Questions
unable to attack enemy objects? 1 Answer
IndexOutOfRangeExeption! This doesent even affect my gameplay, it just is there to be annoying! 1 Answer
NullReferenceException: Error from the GetStyle() - Method 1 Answer
Rayscast from the GameObject that is not the player does not work 0 Answers
UnityAction Vs UnityEvent 1 Answer