CollisionHandlerQueue entry sorting [SOLVED]

I’ve started working on a new game, having lost interest in my last one, and in this game I have some actors that I need to keep on top of terrain in a similar fashion to what’s done in roaming ralph.

There’s one sticky bit, though. It’s a racing game and the terrain may have loops or spirals or some such that would put the actor technically below the terrain it needs to fall up onto, if you get what I was saying.

I figured this wouldn’t be a big problem and I cracked open roaming ralph to look at his groundray code and I saw something that surprised me.

        entries = []
        for i in range(self.ralphGroundHandler.getNumEntries()):
            entry = self.ralphGroundHandler.getEntry(i)
            entries.append(entry)
        entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
                                     x.getSurfacePoint(render).getZ()))

That block of code sorts through the entries in the collision handler, I think by the Z of the point of collision. How does that compare to just calling sortEntries() on the collision handler? Why is this much more complicated sorting system in use?

I’d love to know, if anyone would be kind enough to supply an answer.

Roaming Ralph is actully really out of date (and at the time, really bad code style)… best off to just look at astelix collision examples.

discourse.panda3d.org/viewtopic.php?t=7918

sortEntries() would sort by distance along the ray, whereas the sort function here sorts by distance along the Z-axis. In the case that the ray was not pointing directly along the Z-axis it would make a difference.
Maybe they just wanted to make especially sure of the result. :slight_smile:

I figured it was one of those two possibilities, actually. And here I learn it’s both. Alright then, sorting by distance along the ray is what I will want for my game, because of the track turning upside down and etc. Thanks guys.