I have a 2D top down tank game and my problem is if i shoot with the tank the bullet(Shell) collides with the tanks hull, the shooting is based on a cloning system which clones the Shell takes the transform and rotation and fly out of the tank, but like the shell the shell clone is colliding with the hull too and really weird things happen.Here is the script:
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public Rigidbody2D projectile;
public float canshoot = 1; // Can the tank shoot(1) or can't(0)
public float _Reloadtime = 15;
public float reloadleft;//Reload time left
void Start(){
reloadleft = _Reloadtime;//Sets reloadleft to 15secs
}
void Update() {
if (canshoot == 1)// The tank can shoot
if (Input.GetKey (KeyCode.Space)) {
Rigidbody2D clone;
clone = Instantiate (projectile, transform.position, transform.rotation) as Rigidbody2D;
clone.velocity = transform.TransformDirection (new Vector2 (0, 1 * 10));//Shooting...
canshoot = 0;//The tank can't shoot
}
if (canshoot == 0)
reloadleft -= Time.deltaTime;//Reloading...
if (reloadleft <= 0) {
canshoot = 1;//Reloaded the tank can shoot again
reloadleft = _Reloadtime;//Reloadtime is 15secs again
}
}
}