[SOLVED]More about collisions

I’m working the collision checking and I’m stuck with a problem: I need the Actor that is collided into but I get just a nodePath, and I’m unable to get the actor object by navigating the tree

if (self.queue.getNumEntries()>0):
            for i in range(self.queue.getNumEntries()):
                entry = self.queue.getEntry(i)
                obj1=entry.getIntoNodePath().getParent()
            print entry.getIntoNodePath().getParent()
            print type(entry.getIntoNodePath().getParent())

This returns:
render/Armature_male
<type ‘libpanda.NodePath’>

and what I need it to return somehow is
Actor Armature_male, parts = [‘modelRoot’], LODs = [‘lodRoot’], anims = [‘walk’]
<class ‘direct.actor.Actor.Actor’>

Maybe it helps if I put how is defined the actor and the collsion sphere:

csprof0 = CollisionSphere(0, 0, 0, 1.5)
    cnpprof0 = prof0.attachNewNode(CollisionNode('csprof0'))
    cnpprof0.node().addSolid(csprof0)
    cnpprof0.show()
    
    self.profList.insert(0,prof0)

Thanks in advance for any help

It could be an option to use setPythonTag to store the actor in the nodepath:

# When its created
yourModel = Actor(blah, blah dee blah)
yourModel.setPythonTag("actor", yourModel)


# When you need it
if (self.queue.getNumEntries()>0):
            for i in range(self.queue.getNumEntries()):
                entry = self.queue.getEntry(i)
                obj1=entry.getIntoNodePath().getParent()
            
            actor = entry.getIntoNodePath().getParent().getPythonTag("actor")
            print actor

I don’t know whether they’re the best way, but I can attest that the (set/get)PythonTag pair can indeed work for this, as I’m using them myself for a very similar purpose.

(Is there no way to retrieve an actor from its node? I don’t see one, but that seems a little odd to me… o_0)

Thanks, I added the code and it immediatly worked, so I’m using it and I have nothing to complain about, but it seems to me (like Thauma said) that it’s a workaround for a direct method to obtain the actor that, if it doesn’t exist, it certainly should

It’s complicated.

The Actor itself isn’t stored in the scene graph, so there’s no way to retrieve it from the scene graph.

To clarify: Actor is a Python object that extends NodePath, and adds additional functionality to it. Remember, NodePath is a handle to a PandaNode. So Actor is extending the handle to the node, not the node itself.

NodePaths are not stored in the scene graph, but PandaNodes are. When you store the Actor in the scene graph, you are really storing its PandaNode. When you later find the PandaNode in the scene graph, you can wrap a new NodePath around that node (and many Panda functions will do this for you automatically), but it’s not the same object as the original NodePath, and hence doesn’t have the Actor extensions.

Even if Actor extended PandaNode instead of NodePath, however, it still wouldn’t work, because the scene graph is a C++ structure and only the C++ core of the object can be stored in the scene graph, not any Python object that extends it.

David

can this work through python tag?

At least the python tag method does work and I’m happy the problem was not (just) me beeing a newbie in panda

It does seem to. :slight_smile:

(I, admittedly, am not storing an Actor, but rather my container/logic classes, so that I have access to their properties - the damage values of projectiles, for example, or the “push” method of my creature class.

The same tactic should, I would imagine, work for a normal Actor, however.)

Aah, fair enough, and thanks. That makes sense. :slight_smile:

How hard is it to rewrite actor to be in C++?

We’ve talked about doing that, for other reasons. But unless we also make it extend PandaNode instead of NodePath, it’s not going to change this fundamental problem. But making that change would be a major change in its usage and would certainly break any existing Actor code.

David

hmm…

Being backward compatible is always hard.