- Home /
OnCollisionEnter but have colliding object not move the object it collides with
Is it possible to use OnCollisionEnter or detect collision otherwise without having one object affect the position of the other?
i.e., bullet A hits Object B, but Object B does not move, bullet A goes "right through"
OnTriggerEnter with isTrigger checkboxed for the bullet and rigidbody set for both objects:
Vector3 v = new Vector3(0,0,-3);
public GUIText t;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate(v);
}
void OnTriggerEnter(Collider col){
t.text = col.gameObject.name;
}
Answer by Graphicated · Apr 06, 2012 at 09:54 PM
you can set for the GameObjects that are Colliding in the Collider component settings in the inspector "is Trigger = true" and call OnTriggerEnter instead of OnCollisionEnter ... so the colliders will "fly" or go through each other.
so this way Bullet A hits Object B, and Object B does not Move, Bullet A goes through :)
also, try to debug yor collition/trigger
void OnTriggerEnter(Collider col){
Debug.Log("Collision True");
t.text = col.gameObject.name;
}
check the size of the collider ,, is it covering the gameobject? maybe a collider size problem ?
try to debug the collision. replace your function or add the debug line :
void OnTriggerEnter(Collider col){ Debug.Log("Collision True"); t.text = col.gameObject.name; }