Collision is occurring visibly, but is not registering in OnCollisionEnter
I've been trying to get my game to register collisions between my spaceship (the player) and a laser bullet for about a day now. The collisions are working - the ship is being moved by the bullet. However, OnCollisionEnter, OnCollisionStay, and OnCollisionExit all do not work. There is a rigidbody2D on the bullet and the ship, and even when I tried taking off the rigidbody2D that was on the bullet the collisions still did not register (I heard that when 2 rigidbodies collide they don't trigger OnCollisionEnter). I even used the teleportation method (despite my best judgement, I manipulated the position variables directly to move the bullet since the bullet needed the rigidbody to start moving). The teleportation method still would get collisions but would not trigger the functions. Is there something I'm doing wrong? The components on the ship:
Transform
Sprite Renderer
Rigidbody 2D (Dynamic, No Physic Material, Simulated, Discrete, Start Awake, No interpolation, Z rotation frozen)
The player controller script (The script with the OnCollisionEnter being called, posted fully below)
Polygon Collider 2D (No physic material, not a trigger, not used by effector)
The components on the bullet:
Transform
Sprite Renderer
Box Collider 2D (no physic material, not trigger, not used by effector)
My bullet script (Senses whether the bullet is past a dead zone and destroys it; updates bullet position without a rigidbody)
The code for the player controller script which is having issues (The rest of it works fine and does not manipulate this code in any way):
void OnCollisionEnter(Collision col)
{
Debug.Log("Collision");
if (col.gameObject.tag == "EnemyBullet")
{
Debug.Log("Hit!");
}
}
The entire bullet script:
using UnityEngine;
using System.Collections;
public class enemyBullet : MonoBehaviour {
public float bulletSpeed;
Transform currentPos;
void Update () {
currentPos = transform;
currentPos.position = new Vector2(currentPos.position.x - bulletSpeed*Time.deltaTime, currentPos.position.y);
transform.position = currentPos.position;
if (transform.position.x < -10)
{
Destroy(gameObject);
}
}
}
Again, the bullets are working and have been working fine - they fly like they should and they do collide with the craft. I also have no errors in the console. My only complaint is that OnCollisionEnter is not working, so I can't make the ship take damage (Or rather, I'm not experienced enough to figure out another way...). Thank you for your help! I appreciate it!