T
T
Timur9757872022-01-20 20:37:32
Unity
Timur975787, 2022-01-20 20:37:32

The object ignores objects with a specific tag. What is the reason and how to fix it?

I have a script (trigger) that should turn the player to an object with a specific tag, but it ignores the objects. It works with other objects with the tag. Why and how to fix it?
Trigger script:

using UnityEngine;

public class Player : MonoBehaviour
{
    public Transform npc;
    public Transform player;
    public string Tag;
    private void Update()
    {
        transform.position = player.position; 
        transform.rotation = player.rotation;
    }
    public void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.transform.gameObject.CompareTag(Tag)) 
        {
            npc = collision.transform;
            Quaternion lookRotation = Quaternion.LookRotation(Vector3.forward, npc.position - player.position);
            player.rotation = Quaternion.Euler(0, 0, lookRotation.eulerAngles.z + 180);
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Ukrainskiy, 2022-01-20
@Timur975787

You need to poke in the layer collision matrix

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question