0
votes

I have a collision script that's attached to my player (mainCamera) and bullet prefab.

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.

1
I found the problem, it's OnCollisionEnter not onCollisionEnter. However, the problem with the sphere passing through the floor and walls are still a problem.Emugod
"I found the problem" then please delete the question to save the time of moderators. if you have a new actual question, go ahead and ask a new question, be specificFattie

1 Answers

0
votes

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.