x


Scaling a collider to set an event

Im trying to create a visual effect where a bunch of cubes play an animation when a growing spherical trigger engulfs them.

Let me explain further...

various scattered cubes are laid out. they all have a script that has collision detection on them that tells them to play an animation once the collision happens.

function OnCollisionEnter(Collision : Collision){
 if(Collision.gameObject.name == "BlockBuilder"){
  Debug.Log("Entered Trigger");
 }
}

Then there is a sphere collider that has an animation that scales its radius to a huge value over 2 secs.

In theory, what should happen is once a cube is inside the sphere because it has scaled over it, the script should run - but it's not. The only way I can get a detection to happen is if I put rigid bodies on each but then the sphere just pushes the cubes along.

I've tried using a trigger, but to do so I need to place the script on the sphere object and then it will require a giant list of pre-defined objects to check to see which cubes to affect, which I don't want - I want it to be dynamic.

any ideas on how to do this? the easiest way I can think of is somehow making the rigid body not affect anything, is that even possible?

thanx!

Thank you so much for helping out! so here is the script that works:

function OnTriggerEnter(Col : Collider)
{
    if(Col.gameObject.name == "BlockBuilder")
    {
        Debug.Log("Entered Trigger");
    }
}

What I needed to do was make it a trigger so that it doesnt push anything around, but still leaving the rigid body there. It works like a charm now! Thank you so much for the help!

more ▼

asked Jan 08 '11 at 08:51 PM

stiltskin gravatar image

stiltskin
17 2 4 8

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

1 answer: sort voted first

Does the code you posted actually compile? (I haven't tried it, but I'd expect the variable name 'Collision' to generate an error. I don't use UnityScript though, so maybe there's something going on there that I'm not aware of.)

Regarding the problem you describe, I'd expect that if you made the sphere collider a trigger and then used OnTriggerEnter() rather than OnCollisionEnter(), it would work. Have you tried that?

more ▼

answered Jan 08 '11 at 09:11 PM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

yeah, it compiles and works - as long as I turn on rigid bodies everywhere. but like I said, the problem that I get is that the big sphere ends up just pushing the cubes around (even though the collision happens anyway). Basically you end up seeing the event happen but at the same time they get pushed around.

I have tried with a trigger but could not get it to work. Maybe I'm using the formatting badly. I have no clue. The only reason why I have been focusing on collision though is because I assumed that the trigger itself is the one that supposed to have the OnTriggerEnter function on it.

Jan 08 '11 at 11:31 PM stiltskin

I think both objects involved in a 'trigger' collision receive an OnTriggerEnter() message (you can check the docs to make sure). In any case, although I haven't tried it, I think making the sphere a trigger should work; if it's not working, you likely have something set up wrong. (Also, I'm a little surprised that UnityScript will let you give a variable the same name as a type, but like I said, I don't use US so I might be missing something there.)

Jan 08 '11 at 11:51 PM Jesse Anders

Ok, this is awesome. I got it working with the trigger. It looks like you still need the rigid body but once you make it a trigger it doesnt move anything around anymore. Thanx!

Jan 09 '11 at 12:03 AM stiltskin
(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
x1765
x1020
x401

asked: Jan 08 '11 at 08:51 PM

Seen: 1054 times

Last Updated: Jan 09 '11 at 12:35 AM