Can't kill off my player when the player enters the trap.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DeathTraps : MonoBehaviour {

    public Transform player;

    void OnCollisionEnter(Collision collision)
    {
        if( collision.gameObject.tag == "Player" )
        {
            Destroy(collision.gameObject);
        }
}
}

3063086--230224--Code.PNG
3063086--230225--Code5.PNG

Stupid question,but have you assigned tag to player’s gameobject?

yup :confused:

You should be using OnTriggerEnter

Your trap should have a trigger collider on it. Your player probably should just have a normal non trigger collider. One of them needs a rigidbody (likely player)

You don’t want both colliders set as trigger, just the trap.

tried that still doesn’t work

Tried what? Show us code if you changed anything there.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DeathTraps : MonoBehaviour {

    public Transform player;

    void OnTriggerEnter(Collider other)
    {
        if( GetComponent<Collider>().gameObject.tag == "Player" )
        {
            Destroy(other.gameObject);
        }
}
}

sorry just changed the code now but yeah player moves through the trap

Did you turn off the player trigger and add a rigidbody to the player if they didn’t have one?

Also, is this a 2D or 3D game?

Oh, I see another issue. Why are you using GetComponent ?

Change that to “other”. If you use GetComponent you are telling it to get the Traps collider and not checking what enters your trap.

Also, compareTag is usually better to use instead of =, but that’s a minor detail to get this working for you.

it’s 2D but i’m using 3D colliders as they seem to work better for this type of game and i have tried the 2D colliders and not entirely sure XD thats my error as i forgot what i needed to put there. Also tried the rigidbody thing didn’t work

You might have missed where I mention the GetComponent thing as I added it after.

I’m unsure how well the 3D stuff works with 2D, since there is also a 2D rigidbody. That may be why it doesn’t work even when everything is correct, but not sure.

Also, i need help with this script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class Cell : NetworkBehaviour {

    public float Speed;

    void Update ()
    {
        if (!isLocalPlayer)
        {
            return;
        }
           
        //        DrawRay ();
        Vector3 Target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
        Target.z = transform.position.z;
        transform.position = Vector3.MoveTowards(transform.position , Target , Speed * Time.deltaTime/transform.localScale.x) ;
        transform.rotation = Vector3.MoveTowards(transform.rotation , Target , Speed * Time.deltaTime/transform.localScale.x) ;
    }




}

i am trying to get the player to rotate but i forgot what i needed for the rotation XD