i'm working on a 2D shooting game but my arrow just goes right through the enemy.
i have a bullet prefab with Rigidbody2D,: set as Dynamic, and a Box collier2d set as trigger. if (CrossPlatformInputManager.GetButtonDown ("Fire1")) Fire (); } void Fire() { var firedBullet = Instantiate (bullet, barrel.position, barrel.rotation); firedBullet.AddForce (barrel.up * bulletSpeed); }
then the enemy also has a Rigidbody2D set as Kinematic (changed from Kin toDyn but it wouldn't spawn with Dynamic) 2Dbox collider, not checked as trigger i have this script to kill is when it collides with bullet.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Enemykill : MonoBehaviour {
//use this for initialization
void Start () {
}
//update is called once per frame
void Update () {
}
void OnCollisionEnter2D (Collision2D col)
{
if (col.gameObject.tag.Equals ("Bullet"))
{
Destroy (col.gameObject);
Destroy (gameObject);
}
}
I have a simple move script for the enemy who just flies straight up.
public class enemyMove : MonoBehaviour { //speed -x for left, x for right, y for up and -y for down public Vector2 speed;
Rigidbody2D rb;
//use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody2D>();
rb.velocity = speed;
}
//update is called once per frame
void Update ()
{
rb,velocity = speed;
}
} i've tried several scripts and setting in rigidbody and 2d box collider but it the bullet just go right through no matter what i change. i've been stuck on this for a few days now and would appreciate any help.
Your answer