system
October 24, 2010, 9:36pm
1
Hello all, I am having a bit of an odd problem.
I am attempting to write a gun firing script, the problem is when the player fires the bullet hits their own ships collider. Heres the code:
Rigidbody instantiatedProjectile = Network.Instantiate ( bullet, firepoint.transform.position, transform.parent.rotation, 0 ) as Rigidbody;
instantiatedProjectile.velocity = gameObject.transform.TransformDirection( 0,0, speed ) + gameObject.transform.parent.rigidbody.velocity;
Debug.Log(gameObject.transform.parent.name);
Physics.IgnoreCollision( instantiatedProjectile.collider, gameObject.transform.parent.collider, true );
This is attached to a gun object, which is a child of the players ship. Basically IgnoreCollision does not seem to be effecting the bullet. Any ideas why?
system
October 24, 2010, 10:44pm
2
For anyone who has a similar problem here is what I did to solve it:
I attached this script to my bullet object:
public void AddCollider(Collider c1, Collider c2){
Debug.Log("Ignoring " + c1 + " " + c2);
Physics.IgnoreCollision( c1, c2, true );
}
And then when I instantiated I did this:
boxcol = gameObject.transform.parent.GetComponent<BoxCollider>();
boxcol2 = instantiatedProjectile.GetComponent<BoxCollider>();
capsulecol = gameObject.transform.parent.GetComponent<CapsuleCollider>();
capsulecol2 = instantiatedProjectile.GetComponent<MeshCollider>();
bullethits = instantiatedProjectile.GetComponent<IgnoreHits>();
bullethits.AddCollider(boxcol, boxcol2);
bullethits.AddCollider(boxcol, capsulecol2);
bullethits.AddCollider(capsulecol, capsulecol2);
I have two explinations for why this may work when other attempts did not:
Now I am assigning the IgnoreCollision in the bullet object instead of the gun object
Both objects have 2 colliders, so I make sure they all ignore eachother