Help with Triggers please guys banging my head against a wal

Heya guys thanks in advice for the help (If i receive any), But i’ve basically only just picking up python and have managed to get a white box, char model (No animation) walking around with crap collision detection. But the next step is Triggers, All i want to do is when the model gets to a certain point (X,Y,Z) then a text box comes up. But it’s prooving to be a right pain the ass.

If you would like to see my code I have no problems with that, but hopefully i snippet of how it could be done is really all im after. tnx guys!

idea1: create an collision solid , like a sphere and add it at desired position. check your collision entries if your box collides with the sphere, ->display textmessage
if textmessage is already displayed . do nothing…
something like that… i’m little bit too tired to put it into code, thought^^.

yes you can do this via a collision face detection or if you just wanna get a trigger at a point, calc the dis between the player and the trigger point. and say start to trigger when you get into your liked distance. on that way your calling a sphere around your trigger point. if a sphere is enough for you to trigger.

@ditus: very true^^there also is the good o’l way
a very simple way of doint so just create a dummynode at the position you want.
something like this

#create a dummynode and position it to where you need it
triggerNode = render.attachNewNode()
triggerNode.setPos(10,42,36) #whatever position you want

then create a task which checks the distance between those 2 nodes every frame or every x-seconds

def triggerChecks(task):
    distance = triggerNode.getDistance(yourPlayerNode)
    if( distance < TriggerDistance ):  #TriggerDistance is the distance between objects you use to trigger
        #display text here
    return Task.cont

that would be a very basic way to “trigger” things. it should be ok if you dont use hundrets and thousands of triggers like that.
if you want to, you would need to use something more efficient. dont worry panda provides everything :stuck_out_tongue: its just not as easy to use. for example pandas collision system. if you structure your data the right way you can use many thousands triggers in a single map.

code is untested but should give you an idea what we’r talking about :slight_smile:

Thanks mate i’ll give it a go!

Ok i’ve “attempted” it lol… think im a complete noob- basically i’ve tried to do it like this:

    #second person
    object =  loader.loadModel('models/skeletons')
    object.reparentTo(render)
    object.setPos(-10 ,10,10 )
  • loads in another model meant to be my trigger… lol

and that after my first “world” class I have:

def triggerChecks(task):
distance = hat.getDistance(object)
if( distance < object ): #TriggerDistance is the distance between objects you use to trigger
mySound.play()
return Task.cont
run( )

like you suggested, but obviously it doesn’t work (it compiles though!) because i spooned it :frowning: plz the last nudge mate ! :smiley:

Comparing a float number (distance) with an instance of NodePath (object) won’t work.

enn0x

is there any way i can get this simple code to work please mate?

Instead of comparing distance to object, you need to compare it to a number that represents (roughly) the size of the object. You’ll have to figure out this distance yourself, based on the size of objects in your game.