x


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;

}
more ▼

asked Apr 06 '12 at 09:40 PM

ina gravatar image

ina
3.3k 492 550 602

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
    }
more ▼

answered Apr 06 '12 at 09:54 PM

Graphicated gravatar image

Graphicated
152 1 3 4

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; }

Apr 06 '12 at 10:12 PM Graphicated
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2500
x1879
x1795
x1704

asked: Apr 06 '12 at 09:40 PM

Seen: 604 times

Last Updated: Apr 06 '12 at 10:13 PM