Ok, so I have been playing with creating guns in unity and I want to create bullet penetration, I have seen a few ideas on how to implement this but they are all for raycast guns, I'm spawning a bullet object and launching it. The only way I can think to do this would be to make the collider for the bullet a trigger upon colliding an object with the tag "Penetrable", However this rarly actually works and it causes the whole game to lag, any ideas?
Script:
using UnityEngine;
using System.Collections;
public class BulletObject : MonoBehaviour {
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Penetrable")
{
collider.isTrigger = true;
print (this.gameObject.name +" Has had it's spherecollider removed");
}
if (collision.gameObject.tag == "Terrain")
{
print (this.gameObject.name + " has hit the ground!");
Destroy (this.gameObject);
}
}
void OnCollisionExit(Collision collision)
{
if (collision.gameObject.tag == "Penetrable")
{
collider.isTrigger = false;
print (this.gameObject.name + " Has had it's spherecollider re-added");
}
}
}
↧