I am trying to have a bullet fly out my ship.
However, the bullet doesn’t move and I think I have the error down to the fact, that it collides with my ship.
This is the Firing-Coroutine:
IEnumerator FireGun()
{
GameObject bulletClone = Instantiate(bullet, transform.position, player.GetComponent<Transform>().rotation);
bulletClone.GetComponent<BulletBehavior>().damage = damage;
bulletClone.GetComponent<Rigidbody2D>().AddForce(bulletClone.transform.up * bulletSpeed);
Physics2D.IgnoreLayerCollision(8, 9);
Debug.Log(bulletClone.transform.up * bulletSpeed);
Debug.Log(bulletClone.GetComponent<Rigidbody2D>().velocity);
Debug.Log(Physics2D.GetIgnoreLayerCollision(8, 9));
yield return null;
}
The Player does have the Layer 8, the Bullets do have the Layer 9 and the Log shows those layers get ignored.
Log also shows, that a force of 0,500,0 should be applied, but the velocity is 0,0,0.
This is the error:
““MissingComponentException: There is no ‘Collider’ attached to the “Player” game object, but a script is trying to access it.
You probably need to add a Collider to the game object “Player”. Or your script needs to check if the component is attached before using it.””
This is my player:
It clearly has a collider.
Does anybody know what is happening here?
Thanks very much in advance
Jan