Two ways I can think of off hand. One is to create a cube and set alpha to 0. Create a pivot with a small radius to collide with the cube. Then do something like this:
MoveEntity player,x,y,z
UpdateWorld
PositionEntity pivot,EntityX(player),EntityY(player)EntityZ(player)
UpdateWorld
If EnityX(pivot) <> EntityX(player) or EntityY(pivot) <> EntityY(player) or EntityZ(pivot) <> EntityZ(player) Then triggersomething()
The idea is if the pivot doesn't successfully make it to the player's position, then the player must be within one of these trigger cubes. Another way to do it would be to create a variable with x/y/z coordinates and a radius, and see if the player is near the point.
;...Some code here
Type Trigger_Sphere
Field x#, y#, z# ;x/y/z coordinates of the trigger
Field radius# ; radius of the trigger
End Type
Door_Trigger.Trigger_Sphere = New Trigger_Sphere
Door_Trigger\x = 50.0
Door_Trigger\y = 10.5
Door_Trigger\z = -30.2
Door_Trigger\radius = 2
... Some more code here
While Not KeyDown(1)
UpdatePlayer()
If Abs(EntityX(player) - Door_Trigger\x) < Door_Trigger\radius
If Abs(EntityY(player) - Door_Trigger\y) < Door_Trigger\radius
If Abs(EntityZ(player) - Door_Trigger\z) < Door_Trigger\radius
OpenDoor()
End If
End If
End If
...Some more code
RenderWorld
Flip
Wend
The advantage of doing it this way is that you don't actually need to create another entity. Also, you don't need to have a check every single UpdateWorld call. If the triggers only work when a player is pressing a key to open a door, then only check if the player is pressing that key.
I'm also sure there are other ways of doing this, possibly better than these. :)
|