Triggers (Trigger Events)

Blitz3D Forums/Blitz3D Programming/Triggers (Trigger Events)

3DMan(Posted 2010) [#1]
Hi guys!

It's sad to see that my last post was 2 years ago, and I haven't had the time to do anything I wanted in that time, due to lack of time...

Well, I decided I'll get out of the rat race and rip the time a new a-hole and do something I've always wanted with Blitz :]

I created a series of portals (two sided vertical planes) along the level and would like to switch location of an object each time the player goes through these portals, putting the object to different locations depending of the side of the portal entered.

Also remember that since the portals are two sided, when the player enters the portal from one direction it switches the object to a different location than when the player enters the portal from the opposite direction.

The problem also arises when the player enters(colides with) the portal and then while remaining mid portal decides he'll go back, how would I make it so it switches the object back to where it was before entering the portal.
Could I perform some sort of check like IF the player is more than half way through the plane it would switch the object to the new location otherwise remain at the old location, and switch it back to the old location if he decides to turn around and go back in mid portal position.

*as a side note - I want the solution to be as fast as possible, no resource hogging (none of the excess vector checks etc.. like with all the portal plane entity distance check for each portal every frame) *


Apart from that, I'm interested in all sorts of triggers to trigger events possible in blitz. I know we can check EntityDistance,
we can check for Collision and then trigger something, anything else?
Which methods are the fastest?
Pseudocode examples of different sorts of triggers would also be welcome for all us blitz users, to come back here and have them all under one topic.

Thank you guys and looking forward to the answers,
I wish you the best in 2010!


Ross C(Posted 2010) [#2]
You could have two sets of portals. The player has to go through the two sets, a small distance apart (but bigger than the player), in order to trigger the object to get moved. Give each pair of portals it's own flag or variable.

For instance, he hits the first portal, the portals flag gets set to 1. Upon hitting the next portal, again, the portal flag/variable is set to one, for that portal. You check both flags. If they are both set to 1 then you move the item.

You need to set the portals though, so the flag toggles everytime you go through it. AND, these portals only work the one way. If you want the item to go somewhere else upon entering from the other direction, set up another 2 portals.

This method will require more portals, but, you have no vector checking. As long as the player can't fly over the portal areas, or circumvent them, then it should be fine. Oh and i think your best using pivots for portals, and using entity distance to check to see if your withing distance.

In my last project, i forced the character through narrow area, in order to trigger events, and geometry hiding.

Oh and entitydistance is stupidly quick.


3DMan(Posted 2010) [#3]
Hi Ross!

Thank you for replying.
So you think i should use pivots with entitydistance(pivot,player) and choose the nearest one to switch instead of a whole bunch of portals? What do you think is the best way?
The problem with checking for distance is wide coridors,
where the player could go by the extreme of the wall and get by the pivot activation trigger distance, if for instance the pivot is located in the middle of corridor.
Or the distance checked could be too wide for the purpose.

Could you write a line or two of code, for your two portal method (flag and collision checking)?
Also do you think that two sided planes can't be used? And for instance when the player leaves the two portal zone, the last portal left would then be used as the switch for new entity position.

Thank you bro
Greets!


jfk EO-11110(Posted 2010) [#4]
You can have fast portals when you can manage to align them to the world. I mean, If a trigger zone is considered a cube, the Rotation must be 0,0,0. This way you can determine the min and max vertex xyz, store it in an array and do a "is the player inside the trigger box?"-check very quickly. You can visually use these trigger meshboxes in your design app, in the game the box can be deleted after the minmax determination.

I sometimes use ON and OFF triggers. This may be something as Ross said. To reach a new Section, first the player has to cross the OFF box, then the ON box. Now, when he decides (eg. in the middle of the way between the 2 sections) to go back, he will automaticly turn the thing off as his latest action (no matter if it is on or not) within this 2-Box portal trigger. But when he actually reaches the new section, he must have crossed the ON box.

I guess you can use the same principle to position things. Especially when you position them back ANYWAY when the player goes trough the OFF Box.


3DMan(Posted 2010) [#5]
Hi JFK!

Thank you for your answer!
Could you show me how you do it with simple code please?


Zethrax(Posted 2010) [#6]
I'm not sure if this is what you're after, but I have some code in the code archives for double-sided triggerplates using proxy collision objects.

http://www.blitzbasic.com/codearcs/codearcs.php?code=1901

My OBB code may also be useful to you.

http://www.blitzbasic.com/codearcs/codearcs.php?code=1920


3DMan(Posted 2010) [#7]
Thank you for replying guys, I'll take a look at your trigger plate system Bill.


jfk EO-11110(Posted 2010) [#8]
3DMan sorry for the delay, I was AFK.

You really don't need much code. You only need to understand what I mean.

In my exampe I want to turn on (Showentity) a Mirror (CreateMirror) as soon as the player is getting close to it, but still before he can see it of course, because I don' want it to pop in. So there is a zigzag corridor the player is walking trough. There are two boxes intersecting with the corridor in a way that the player must go trough the boxes (and they must be big enough so he will be at least for one frame inside such a box, even in full running speed or so).


Now the trick is very simple: when the player crosses the first box, we hide the Mirror. The Player will then pass/cross the 2nd box later on his way (note, the 2 boxes may NOT overlap). Now we show the mirror. If the player is going to leave the mirror area later, he will first cross the 2nd Box. This will turn the Mirror on again, regardless of the fact that it IS already turned on (!). Then the player crosses the 1st box and this will finally turn it off (hide) again, as it sould be when the player isn't there anymore, in the mirror section.

I don't know exactly how your level design works, but as I already suggested, you could use simple box meshes to define the trigger boxes.

You load them like other map elemets. Then you parse the vertices of these cubes and store the min and max xyz in an array or type.

Finally you check in your game main loop if the player is located inside one of the boxes, by comparing his location with the xyz min max data.

What you need it TFormPoint to get the world coordinates of the vertices. This ia all very basic and if you don't know how to code it then you really should learn these Basics first.

Here's some pseud code:


xmax#=-1000000
xmin#= 1000000
for su=1 to countsurfaces(mesh)
 s=getsurface(mesh,su)
 for i=0 to countvertices(s)-1
  x#=vertexX(s,i)
  y#=vertexY(s,i)
  z#=vertexZ(s,i)
  Tformpoint x,y,z,mesh,0
  x=TformedX()
  y=Tformedy()
  z=Tformedz()
  if x>xmax then xmax=x
  if x<xmin then xmin=x
  ...
 next
next


so this way you can determine the smallest and the biggest X value of any of the vertices of a mesh. Of course you do the same with y and z. this will give you the coordinates of the 8 corners of such a cube. Once determined, the cube mesh may be removed with FreeEntity.

Assuming you have stored the min and max data in arrays named minx#, miny#, minz# and maxx#, maxy# and maxz# you would then do something like this:

x#=entityx(player)
y#=entityy(player)
z#=entityz(player)

for i=0 to count-1
 if x>minx(i) and x<maxx(i)
  if y>miny(i) and y<maxy(i)
   if z>minz(i) and z<maxz(i)
    ; bingo, we're inside cube number i
   endif
  endif
 endif
next

(note: just fixed a typo so if it didn't work before then try again. And added TFormPoint Sample, btw.)