Topic: Setting up a Trigger??

This email request follow a Sound trigger set up by antOn who helped me organse sounds as one passed a different space.

I have some question about setting up a Trigger.  I understand how to create a box and then make it invisible, but I cannot understand how you name it Trigger 1, Trigger 2 etc.  so that it appears in the Objects List?

Re: Setting up a Trigger??

Not quite sure what you want to understand so I will write a detailed tutorial on the triggers.

1) Download the cube model. Make the following settings:
    invisible = true
    Physics (Box) = true
    ghost = true
http://savepic.net/6005548m.jpg

2) Create 3 copies of the cube (Ctrl + D). And rename them (trigger1, trigger2 and trigger3)
http://savepic.net/6009644m.jpg

3)Scripting. Create a main script and open it.
- get our triggers.

--you can do this:
triggers = {getObject("trigger1"),getObject("trigger2"),getObject("trigger3")}

--But better to do it through the loop.
triggers = {}
num_triggers = 3    --the number of triggers.
for i=1,num_triggers do
    triggers[i] = getObject("trigger"..i)
end
--it's the same thing, if done manually:
--triggers[1] = getObject("trigger1")
--triggers[2] = getObject("trigger2")
--triggers[3] = getObject("trigger3")

Now let's write a function entry trigger.

function onEnterTrigger(trigger,entity)
    if isCollisionBetween(trigger, entity) then --if collision
        return true
    end
end

Now, to verify create three cubes. Applied physics them and place them on the triggers. And create the camera.
http://savepic.net/5984044m.jpg

get these cubes.

cubes = {}
num_cubes = 3
for i=1,num_cubes do
    cubes[i] = getObject("cube"..i)
end

Let's do that in contact with triggers, cubes disappeared.

function onSceneUpdate()
    for i=1,#triggers do
        if onEnterTrigger(triggers[i],cubes[i]) then
            deactivate(cubes[i])
        end
    end
end

Result:
http://savepic.net/5987116m.jpg
http://savepic.net/5980972m.jpg

download project.

Re: Setting up a Trigger??

You can also interact with a single trigger.

function onSceneUpdate()
    if onEnterTrigger(triggers[1],player) then
         --...
    end
end

Re: Setting up a Trigger??

Wooow!!!  antOn!!  Thank you so much for the detailed tutorial!  This helps heaps.  Many kind thanks for your efforts!!!!!!!!!!!!