Game Development Community

Tripping Triggers with Items

by Fiona Counihan · in Technical Issues · 11/07/2006 (9:22 am) · 10 replies

Hi,

I have been stuck on this for a while - I am controlling the position of my Item with keyboard input - using setTransform. I want the Item to trip a trigger when it moves inside it - but this doesn't seem to work because I am just setting the transform of the Item as opposed to moving it.
Is there any other way that I can control the movment of an Item object - similar to the way the Player object is controlled, rather than using set Transform?
The way I am doing it at the moment, triggers and collisions won't work.

thanks,
F

#1
11/07/2006 (10:24 am)
Maybe you can use setvelocity() on the item to trip the trigger.
#2
11/07/2006 (1:19 pm)
If that fails you can apply an impulse. Is there a reason your object has to be itemdata?
#3
11/08/2006 (6:11 am)
Hi there,

Thanks for the posts
@ Zod
- well I had the object as a Static Shape - but it needs to be an item, vehicle or player to trip the trigger.
There is no other reason that it needs to be an item though - would I be better off using another type?

@Sean
I will try setVelocity and see if it works thanks.

F.
#4
11/08/2006 (8:33 am)
Fiona - i'd be surprised if the root of the problem was that you're using SetTransform instead of some other way of moving the object. I use setTransform to "teleport" players, and when they leave or enter a trigger as a result, the triggers behave correctly. [verify verify.. yes. they behave correctly.]

Hm, in my very cursory look thru the TGE 1.3 codebase, it looks to me like only Players, Vehicles, and RigidShapes will detect triggers. There seems to be vestigial support for ShapeBase items but it doesn't look like it's being called.

Can you try making your objects RigidShapes ?
#5
11/08/2006 (9:03 am)
Hi Orion,

Thanks for your post, from what I understand it's only since TGE 1.4 that items can also detect triggers - but I hadn't thought about using RigidShapes - I will look into that and see if that helps.

hmm so my problem isn't the fact that I'm using setTransform - well changes things - thats for that info.
yes I'll try changing the object to a rigidShape and see if that helps,

Cheers,
F
#6
11/08/2006 (11:24 am)
There is another way I forgot about. Instead of grabbing it from the ::onTrigger function, try grabbing it in the ::onTickTrigger function. Tick trigger is a loop run every tickPeriodMS. So what may not call ::onEnter would certainly at some point throw a call to ::onTick. Sample:

function DefaultTrigger::onTickTrigger(%data, %trigger)
{
   // Get a count of all the objects inside the trigger area
   %count = %trigger.getNumObjects();

   // Loop through all the objects in the trigger area
   for ( %i = 0; %i < %count; %i++ )
   {
      // Get the object at the index
      %colObj = %trigger.getObject( %i );

      // Now filter for what your looking for
      if ( %colObj.getClassName() $= "Item" )
         doSomething(%colObj);
   }
}
#7
11/08/2006 (11:40 am)
Zod:
I am pretty sure Orion is correct.
and that 1.3 does not have any of these object types in its collision mask.

so that means the %trigger.getNumObjects(); will not include your "Item" type in the count.
so this code will not fire for him.

correct me if I am wrong, but can you not simply add the code to trigger to recognize the item object
(add the item bitmask bit to the trigger's collision bitmap)

then process the trigger code at the item level like the player process's triggers.

I seem to remember doing this.
#8
11/08/2006 (11:46 am)
Badguy -
Quote:can you not simply add the code to trigger to recognize the item object

from my reading, it's more like the objects are responsible for checking if they're in a trigger, versus the trigger checking for objects, but theoretically, yeah.
#9
11/08/2006 (12:38 pm)
Fiona the best solution would be to just script your own trigger and manually do bounds checking on an imaginary box. If you look up the "Container Search" functions theres facilities for doing arbitrary box bounds checking. depending on your situation, this may be adequate. this would also be even more efficient if your triggers are being tripped sequentially as you can programmatically start and stop the bounds checking whenever you want. the good thing about this is you wouldnt be restricted to any particular object class.

does that make sense? comments?
#10
07/27/2009 (1:42 pm)
I have 1.5.2 and I don't think items can trip triggers. I have been trying to do so with no luck. I think it will require engine changes.