简体   繁体   English

碰撞和碰撞器无法正常工作

[英]Collisions and Colliders not working properly

I have a collision script that's attached to my player (mainCamera) and bullet prefab. 我的播放器(mainCamera)和项目符号预制件上附加了一个碰撞脚本。

void onCollisionEnter(Collision collision)
{
    Debug.Log("Collision running");
    if(collision.gameObject.tag == "Enemy" && this.gameObject.tag == "MainCamera")
    {
        Debug.Log("Hit Enemy");
        if (Controller.Health > 0)
        {
            Controller.Health -= .2f;
        }
    } else if (collision.gameObject.tag == "Scenary" && this.gameObject.tag == "Bullet")
    {
        Debug.Log("Bullet hits Scenary");
        Destroy(this.gameObject);
    } else if (collision.gameObject.tag == "Enemy" && this.gameObject.tag == "Bullet")
    {
        Debug.Log("Bullet hits Enemy");
        Destroy(this.gameObject);
        EnemyScript.Health-=.2f;
    }

}

None of my debug logs are being set off. 我的调试日志都没有被取消。 I have proper tags for all of the objects, a rigidbody and sphere collider on the sphere bullet, a sphere collider on the camera, mesh colliders on scenary, and box collider on the enemy which is a cube. 我对所有对象都有适当的标签,球体子弹上的刚体和球体碰撞器,相机上的球体碰撞器,场景中的网状碰撞器和敌人(立方体)上的箱体碰撞器都有正确的标签。 None of my is Triggers are ticked. 我的触发器都没有勾选。 The bullet also has gravity, and it falls after a certain point. 子弹也具有重力,它会落在特定点之后。 It can collide with the box and stop; 它可以与盒子碰撞并停止; however when it hits the wall plane or the floor plane, the bullet falls or goes through sometimes, but also sometimes works and hits the wall and stops or hits the floor and stays there until it gets destroyed. 但是,当子弹撞击墙壁平面或地板平面时,子弹有时会掉落或穿过,但有时也会起作用并撞击墙壁,然后停止或撞击地板并停留在那里直到被摧毁。 Not entirely sure where the problem is. 不能完全确定问题出在哪里。

The problem with the wall or floor is that unity check for physics in fixed Updates , so if you don't put your moving , etc logic in fixed updates this problem occurs. 墙壁或地板的问题是在固定更新中统一检查物理,因此,如果不将移动逻辑等固定更新中,则会发生此问题。 also try this , add a physic material to your bullet. 也可以尝试此操作,将物理材料添加到子弹中。

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

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