x


Detecting collisions between blocks?

Is there any other was to detect collisions between two objects other than this:

function OnTriggerEnter(collision : Collider) { 
   if(collision.gameObject.tag=="Player"){ 
      print("hit"); 
   } 
}

The problem with that is that it requires one of the objects to be a trigger meaning that physics do not apply to it. In the context of my application it means one object will pass through another which i don't really want.

Thanks in advance

more ▼

asked Jun 20 '10 at 02:08 PM

ROM gravatar image

ROM
277 46 49 58

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

2 answers: sort voted first
function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.tag=="Player"){ 
print("hit");
 }
}

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html?from=BoxCollider

Description OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider

more ▼

answered Jun 20 '10 at 02:12 PM

AnaRhisT gravatar image

AnaRhisT
865 30 33 43

I actually looked at this earlier but it didn't seem to work. Is there something about the objects that I have to change? It just never says "hit"

Jun 20 '10 at 02:34 PM ROM

Maybe you don't have colliders/rigidbodies or they're triggered..

Jun 20 '10 at 02:35 PM AnaRhisT

I'm using a sphere and box collider. The following code is applied to them:

function OnCollisionEnter(collision : Collision) { print("hit1"); if(collision.gameObject.tag=="Player"){ print("hit2"); } }

Neither hit1 or hit 2 are printer. its rather odd.

Jun 20 '10 at 02:41 PM ROM

Check if they're trigged. if they're not, try to use a rigidbody.

Jun 20 '10 at 02:43 PM AnaRhisT

How odd, I use rigidbody on one of them with the default settings and it works. I change the settings so the block doesn't move and it stops working. Hmmmmm...

Jun 20 '10 at 02:52 PM ROM
(comments are locked)
10|3000 characters needed characters left

You can use OnTriggerenter, OnTriggerStay, OnTriggerExit, OnCollisionEnter, OnCollisionStay, OnCollisionExit :).

more ▼

answered Nov 30 '12 at 04:53 PM

Nicolas 3D gravatar image

Nicolas 3D
1

(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:

x2584
x2013
x1765
x1019
x42

asked: Jun 20 '10 at 02:08 PM

Seen: 8902 times

Last Updated: Nov 30 '12 at 04:53 PM