Thanks for the tip! I’ll give it a shot.
EDIT: a little bit of fumbling and searching later, I’ve realized I don’t know how to use vectors in Panda yet. I remember the basics of vectors I learned in school, but the API reference isn’t very helpful on this point. Is there a concise tutorial somewhere I can take a look at? I am going to go hunt through the code in the sample programs to see what I can find. Mostly, Vec3 seems to be used with light, but what are the three values in the parentheses? I would have thought vectors needed a lot more numbers to be described in 3D space, since they have 3-point origins, directions (either by passing through another 3-point, or perhaps with two angles) and magnitudes all at once.
EDIT 2: Ah, I see. Some quick experimenting with lighting reveals to me that Vec3(-50, 0, 0) makes light travel from the top of the X axis downwards, and likewise for all other coordinates. I imagine that these are vectors of infinite magnitude, since there is no origin, target or magnitude in the values; changing one value doesn’t seem to matter if the other two are at 0. Then again, maybe that’s just because it’s lighting. I’ll have another look at the API to see if I can make some sense of the methods now.
EDIT 3: Enlightenment! I should calculate the X and Y differences, and use them as the X and Y components in a vector with a Z value of 0 (assuming it’s all on the same level), and then use .angleDeg() on a vector with something like (0, 10, 0) (to represent a straight line going up the Y axis from the origin, which would in theory be the player’s location), which would give me the heading which the NPC would then use. Does that sound right?
EDIT 4: All right, now onto the next problem. I’ve got a giant collision sphere around my NPC, and I want to turn the NPC away from the player when the player collides with this giant sphere. Problem is, I can’t seem to get the coordinates from the player. As it is, the player has a solid with an IntoCollisionMask, and the NPC with a FromCollisionMask, because I found it inconvenient to give the NPCs IntoCollisionMasks, given my setup. I understand that my code is failing because I am trying to query the position of the player’s CollisionNode, as this apparently isn’t possible, but I am unsure of how to get the player’s NodePath from the CollisionNode, since the CNode is attached to the player, which is in turn reparented to the player’s NodePath. Should I use .getParent(2) for this? The code I use for this is the following, as a part of a continually running task:
for i in range(self.ghostFleeing.getNumEntries()):
entry = self.ghostFleeing.getEntry(i)
if (entry.getIntoNode().getName() == "pacmanHunt"):
pacX = entry.getIntoNode().getX()
pacY = entry.getIntoNode().getY()
ghostX = self.ghost.getX()
ghostY = self.ghost.getY()
vecX = ghostX - pacX
vecY = ghostY - pacY
huntVec = (vecX, vecY, 0)
fleeHeading = huntVect.angleDeg(Vec3(0, 10, 0))
self.ghost.setH(fleeHeading)