Issues with a collision segment

Hi there, I am facing some problems trying to use a collision segment.

When I call sort/clear I am receiving an assertion error, it says that entry does not have into information. I print the entry and all seems ok.

Using the debug I found that the segment is missplaced, but I can’t find why. The collision segment was added to a collision node attached to the base camera. I am setting pointA as base.camera.getPos() and pointB as a model.getPos().

So my questions are:

  1. Is there anything I should take care with, considering the positioning?
  2. Any ideas on why this assertion exception is being raised?

Thanks in advance.

It sounds like there is some logic or math error in your code, but I don’t think we can give you any useful advice with such a generic question. Perhaps you can narrow your question down to something more specific?

David

There is no math involved, I am just setting one point as base.camera.getPos() and the other as somemodel.getPos().
I would expect this would create a segment from the camera to the model.

My question is, what can be going wrong with this? the getPos method will return the position on the world or relative to the some other system (for instance scaled)?

Thanks in advance.

getPos() returns the position relative to the node’s parent. In Panda, each node potentially defines a new coordinate space, so if all of the nodes are parented to render (for instance), they’re all in the same (global) coordinate space, but if they have different parents then they might be in different coordinate spaces.

This is a potential for confusion, but the error that you describe doesn’t sound like it’s necessarily due to getting the wrong values for start and end. It could be any number of other things. From what you say, it sounds like it’s complaining that you’re trying to ask a CollisionEntry for its into point, and it either wasn’t involved in a collision, or it was involved with a collision that didn’t compute an into point.

As to how you ended up with such a CollisionEntry when you expected to have a CollisionEntry that had an into point, for that we can only offer vague guesses.

David

Thanks for the reply, I am not really worried about the AssertionError, as the ray is not positioned.
I didn’t reperent the camera to the render, but I would assume it is done automatically.
I am using flattenLight on the model after the scale, I do not believe this could create problems, tought.

I will keep trying.

Building on what drwr said, have you tried setting point B to be “model.getPos(render)”? (Note the addition within the brackets.)

This doesn’t work with an Actor. I tried with the camera and it worked.

I’m also encountered with these problems sir but im searching many sites and nice having here, im kinda having lot of difficulties and wonder if there is logic or mathematical error engage…

Can u help me guys?
thanks!


I am proud of the fact that I the one who invented weapons like combat knives.

Well, could you give us some details about your problem, please?

In general, however, each NodePath essentially defines its own coordinate space: objects can be said to be in a given position relative to it. In particular, objects that are parented (either directly or indirectly) fall under its coordinate space. As a result, moving the parent object results in its children being moved, and an object being at position (0, 0, 0) means that it’s at the same position as its parent (not necessarily at the global origin).

However, if you want an object’s position (or H, P or R, etc.) relative to another object (such as the root node), simply call “getPos()” (or “getH(…)”, etc.), such as “getPos(render)” to get an object’s position relative to the root node named “render”.

(Please note: it’s possible that I am in error in some of the above; my apologies if this is the case, and I stand to be corrected.)

First, thanks for the clarification.
Here is how I load/place the model:

  self.player = Actor(
    mydir+"/graphics/"+playerClass+"/"+playerClass+".egg",
    annimationDict
  )
  self.player.setScale(self.scale)
  self.player.flattenLight()
  self.player.setPos(self.xTranslation, self.yTranslation, self.zTranslation)
  if (self.serverSide == False):
    ClickableObject(self)
  self.player.reparentTo(render)
  self.player.setH(self.lookingAngle)

Then I Position the camera:

  angle = radians(self.charRef.getLookingAngle())
  camX = self.camDist * sin(angle)
  camY = self.camDist * cos(angle)

  base.camera.setPos(self.charRef.getPos() + (x, y, self.camHeight))
  base.camera.lookAt(self.charRef.getPos() + (0, 0, 2.5))

charRef is a reference to the Player object, that holds the model.

Finally here the segment is place/created. After reading your explanation, I believe the problem is here, when I attach the new Node:

  self.__cameraCollisionNode = CollisionNode('cameraRay')
  self.__cameraNP = base.camera.attachNewNode(self.__cameraCollisionNode)
  self.__cameraCollisionSegment = CollisionSegment()
  self.__cameraCollisionSegment.setPointA(self.charRef.getPos())
  self.__cameraCollisionSegment.setPointB(base.camera.getPos())
  self.__cameraNP.show()
  self.__cameraCollisionNode.addSolid(self.__cameraCollisionSegment)
  self.__cameraCollisionNode.setFromCollideMask(globals.visionBlockingObjectsMask)
  self.__cameraCollisionNode.setIntoCollideMask(globals.noOperationObjectsMask)

  self.__cameraCollisionQueue = CollisionHandlerQueue()
  base.cTrav.addCollider(self.__cameraNP, self.__cameraCollisionQueue)

So, if I get the position relative to the Render, would it work? I tried, but actor getPos() is not working with an argument. Probably I need to find the actor NodePath?

Thanks in advance.

Hmm… Is “charRef” a reference directly to self.player? If so, then that shouldn’t be an issue - it seems that self.player is parented directly to render, so it should be in render’s space.

Instead, I’d suggest as the poster above did: get the your camera node’s position relative to render. In other words:

self.__cameraCollisionSegment.setPointA(self.charRef.getPos())
self.__cameraCollisionSegment.setPointB(base.camera.getPos(render)) 

I’m not at all sure of why “getPos()” isn’t working with an Actor - although I’ll confess that the API reference is throwing me off a bit by showing Actor as not being a descendant of NodePath or PandaNode, yet still having methods like “reparentTo”… o_0

To one of those more expert than myself in the inner workings of the engine: what is going on here?

[edit]
A quick experiment on my end found that “getPos(render)” called on an Actor seems to work, so unless we’re using different versions and they differ on this point, that shouldn’t be a problem.