- Home /
Ignore collision
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
}
}
}
Answer by AuraCS · Aug 06, 2014 at 02:47 PM
I guess that you want a way to ignore some specific collisions. Maybe you can try this:
Physics.IgnoreCollision(collider1, collider2, ignore);
Your answer
Follow this Question
Related Questions
Find cardinal direction of collision based on 2D Cartesian coordinates 1 Answer
2D Triggers and Collisions not working as expected. 2 Answers
How would I move an object towards the mouse but not stick to it. 1 Answer
Unity2D collision problem 3 Answers
Check if a Collider2D is hit by a Trigger Collider2D 1 Answer