Picker question - Answered!

Hi :slight_smile:

I’m having a problem using the picker class.

You see: I have made a class in my game that loads a model inside of it (self.model) and then sets the model’s tag to “pickable”.

The thing is that when I click on the model, the picker picks the model and not the object, making impossible for me to use it for anything.

Part of my object’s code:

class PathNode():
        def __init__(self, x, y, height, steps, jump, fall, world):
        self.model = loader.loadModelCopy("T_Water")
        self.model.setPos(x * border, y * border, height + .1)
        self.model.setScale(.2, .2, 2)
        self.tiles = world.Cterrain.tiles
        self.calculate_path(x, y, self.tiles[x][y].height, steps, jump, fall, world)

(makePathNode and makePickable tags the model to be clickable AND to be recognised as a piece of path)

I’ve tried inheriting from NodePath and using something like “self = loadModel…” (Eliminating .model from the equation), but then I cannot use new properties (And I’m not sure it will work).
I’ve also tried reparenting the model to the object and the object to render, with no success.

Does anyone have an idea that I could use?

Thanks a lot,

{} {} }{

One way would be to use a lookup table (aka dictionary). When creating instances of your class “PathNode”, register them like this:

lut = { }
o = PathNode( )
lut[ o.model] = o

Later, if your picker know a model you can retrieve the PathNode instance:

o = lut[ picked_model ]



It worked perfectly :smiley: