简体   繁体   English

触发器未检测到与其他对撞机的碰撞

[英]Trigger is not detecting Collisions with other colliders

I have a Rocket GameObject in my scene and I only want it to collide with certain objects, so I made it a trigger and checked for tags when it collided with something.我的场景中有一个 Rocket GameObject,我只希望它与某些对象发生碰撞,因此我将其设为触发器并在它与某物碰撞时检查标签。 It was all going well until I decided to add this feature to my turret, Ive done some testing and the rocket isnt detecting when it collides with Turret object(they are both on Z=0 by the way).一切都很顺利,直到我决定将这个功能添加到我的炮塔中,我做了一些测试并且火箭没有检测到它何时与炮塔物体发生碰撞(顺便说一下,它们都在 Z=0 上)。

Thanks in advance for anyone who helps!提前感谢任何帮助的人!

Here is the Rocket Script:这是火箭脚本:

void OnTriggerEnter2D(Collider2D other)
{

    UnityEngine.Debug.Log("Collision Detected with" + other);
    if (other.gameObject.tag == "Player")
    {
        PlayerController.health -= 75.0f;
        Die();

    }

    if (other.gameObject.tag == "Boss 1")
    {
        Boss1Controller.health -= 100;
        Die();
    }

    if (other.gameObject.tag == "Turret")
    {
        Destroy(other);
    }
}

And here are a few images of the Turret Game Object and the Rocket GameObject:以下是炮塔游戏 Object 和火箭游戏对象的一些图像:

炮塔预制件

火箭预制件

Never mind, I figured it out, it turns out that triggers don't work with Edge Colliders2D so I just used a Polygon Collider2D instead.没关系,我想通了,事实证明触发器不适用于Edge Colliders2D ,所以我只使用了Polygon Collider2D The shape is isn't as perfect as before but it's good enough.形状不像以前那么完美,但已经足够好了。

Rookie Mistake, sorry.新手错误,对不起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM