Animations and posing...

I am sitting with a problem where I have animated a door in max to open and close and I have exported the model as 3 .egg files: door.egg door-open.egg and door-close.egg. The problem I am sitting with is that I target the door first-person-shooter style and click to activate the animation. The door then closes (from its default open state). Now the only way I can target the door again is by aiming at its original (open) state. The door however has swung closed and is not at its original position anymore. You now have to aim at where the door was to open it again…

Here is targeting the door, the picking code working fine[look at the top right to see the output of the picking code.]:

And here is the door once ive clicked it, and the animation has played finish:

And finally here is targeting the door in its original position:

and you can see that it still thinks that the door is at its original position…

Here is the code I am using to select the object, Actor and model alike:

def selectObject(self, task):
        This task deals with the selecting of objects within the Virtual world (by clicking/targeting them)
        if self.mode == ROAM_MODE:
            #Check to see for a click
            #if (self.mousebtn[0]):
            self.selectedObject = None
            self.selected = 'None'
            self.selection = False
            #Set the position of the ray from the centre of the viewpoint
            self.pickerRay.setFromLens(base.camNode, 0, 0)
            if self.pq.getNumEntries() > 0:
                #if we have hit something, sort the hits so that the closest
                #is first, and get that node
                num = 0
                itemNum =0
                itemFound = False
                chosen = False

                for x in range(self.pq.getNumEntries()):
                    if chosen == False:
                        num = x
                        chosen = True
                        name = getParentName(self.pq.getEntry(x).getIntoNodePath().getParent())
                        for item in self.takable:
                            if item.getName() == name:
                                itemNum = x
                                itemFound = True

                if self.mousebtn[0]:
                    if itemFound == True:
                        self.selectedObject = self.pq.getEntry(itemNum).getIntoNodePath()
                        self.selectedObject = self.pq.getEntry(num).getIntoNodePath()



                    while parent != render:

                        if parent.getParent() == render:
                            self.selectedObject = parent
                            self.selection = True
                            self.selected = parent.getName()

                            #sZ =
                            #if self.selected[len(self.selected)-7:len(self.selected)] == 'Surface':
                                sZ = self.objects[self.selected].getZ()
                            except KeyError:    #perhaps selected an unsavory item?
                            # set pointX,pointY,pointZ if selecting a surface
                            #Gets the point described by pickerRay.getOrigin(), which is relative to
                            #camera, relative instead to render
                            nearPoint = render.getRelativePoint(camera, self.pickerRay.getOrigin())
                            #Same thing with the direction of the ray
                            nearVec = render.getRelativeVector(camera, self.pickerRay.getDirection())
                            pos = PointAtZ(sZ, nearPoint, nearVec)

                            self.pointX = self.holder.getX()
                            self.pointY = self.holder.getY()
                            self.pointZ = self.holder.getZ()

                    if itemFound == True:
                        so = self.pq.getEntry(itemNum).getIntoNodePath()
                        so = self.pq.getEntry(num).getIntoNodePath()

                    parent = so

                    while parent != render:
                        if parent.getParent() == render:
                            so = parent
                            self.highlighted = parent.getName()

        return Task.cont

Well, there’s a problem with picking animated objects…

You might find a workaround when you search the forum on this topic…

But, you’re trying to pick a door. And instead of picking the animated model, how about using simple collision geometry?
Your door has two states: closed and open.
In both cases the position of the door is fixed.
So, if the door is closed put a collision object in the closed position of the door, if it is open put it there.

Knowing this problem now, you should remember to use collision geometry on every animated actor in your later game (for example, if it’s multiplayer you need hitboxes for the players).

hm. jeah… how about doing it the good old way… one door object rotated by code?. so… just rotate the door node, colissino should be just fine this way.

Thanks for the suggestion ThomasEgi;

The problem is that I have MANY door like objects in this one room (cupboards etc.) that have objects that swing; and not all of these objects are nodePath’s, they are, for example, submeshes of the model… So Ive devised a way of dealing with it temporarily (otherwise you cant even take objects out of cupboards - the collision still acts as if the cupboard door is closed when it looks open :frowning: ) and thats included in the above code

Are submeshes no NodePaths? You can easily get the NodePath of a certain part of the model… Check the Manual for more information about that.
For example, if you have a closet that needs to have a door swinging open:


and the door swings open.