creating hot spot

Blitz3D Forums/Blitz3D Beginners Area/creating hot spot

sec05(Posted 2004) [#1]
Hi, want to ask something here.

Anyone knows how to do a hot spot in blitz 3d? What I mean is like when the character touches a certain area in the game, it will trigger an event or something.


TomToad(Posted 2004) [#2]
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. :)


BlackD(Posted 2004) [#3]
It depends if you're talking 2D or 3D. If its 2D, then thats all in programming of your map routines.

In 3D, you're talking about collision events. There are lots of ways to do this, but generally I use a pivot point in space to represent the "hotspot", then use ENTITYCOLLIDED and COLLISIONENTITY to see if that point was hit by the player entity (1) and to carry out actions when that collision occurs (2). Unfortunatey I'm at work so can't post any examples, but have a look at those commands. :)

BlackD


Ross C(Posted 2004) [#4]
You could just use the entitydistance command. If the character is within a certain distance to the hotspot, then trigger the event to happen. EntityDistance is probably a better idea actually. Because you don't really need to use the collision command, as you don't need (or want i'd say) a collision responce.