How To Ignore A Tag
Hello Unity3D.I have a problem with my follow script.The problem is i want my follow script to always and only follow me.But the follow script always follows enemy instead and both the player and enemy has the same tags.Is there a way that i can make the follow script ignore the enemies tag or make it that it always follows me?If So,Can someone please tell me how?(I have been stuck on this for weeks Dx)
Heres the script
#pragma strict
public var player: GameObject[];
var target : Transform;
var enemy : Transform;
var myTransform : Transform;
var moveSpeed = 10;
var rotationSpeed = 12;
var Palm : String = "Palm_L";
var rb : Rigidbody;
var Distance : float;
var closest : GameObject;
var distance = Mathf.Infinity;
var position = transform.position;
function Start () {
player = GameObject.FindGameObjectsWithTag("Player");
enemy = GameObject.FindWithTag("Player").transform;
target = GameObject.FindWithTag(Palm).transform;
target = GameObject.Find(Palm).transform;
Physics.IgnoreCollision(enemy.GetComponent.<Collider>(),enemy.GetComponent.<Collider>());
rb = GetComponent.<Rigidbody>();
}
function Update () {
for (var go : GameObject in player) {
var diff = (go.transform.position - position);
var curDistance = diff.sqrMagnitude;
if (curDistance < distance) {
closest = go;
distance = curDistance;
target = GameObject.Find(Palm).transform;
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
myTransform.transform.parent = GameObject.Find(Palm).transform;
myTransform.transform.position = target.transform.position;
myTransform.transform.rotation = target.transform.rotation;
}
}
}
I do not understand why you just do not change the enemy tag to something other than player like enemy. That will solve the issue.
Answer by DroidifyDevs · Jan 31, 2016 at 06:57 PM
Just change the enemy tag to Enemy and the Player tag to Player. It is silly to use the same tag for such different objects.
I can't don;t that..because my game requires everyone to be a player because my game is a fighting game and i need everyone to be a player in order detect collision.For example.if me and my friend is playing multiplayer and my player is tagged "Player" and his character is tagged "Enemy" and my collision scripts only collide with objects tagged "Player" then how is the character tagged enemy is going to get the collision?)
Your answer
Follow this Question
Related Questions
Flying character rigidbody - can't see any static collider 1 Answer
stop moving forward when collide with player then continue 1 Answer
Need Help With Collider Script. 2 Answers
My player invisble to other players but i can still see other players 1 Answer
How to make OnTriggerEnter Only work for certain Gameobjects? 2 Answers