CollisionRay 'meeting' Position

When I click on a 3d object, I have a collisionray that shows me on what I have clicked. But can it show me where I clicked on it? So the Pos where my Collision Ray “meets” the Object?

You also get a CollisionEntry as the result of any collision test. This CollisionEntry has lots of methods, including getSurfacePoint(), which will tell you the 3-d point of intersection.

David

I tried that already, but I always get this error, so I thought that wasnt right

    print self.myHandler.getEntry(0).getSurfacePoint()
TypeError: Required argument 'space' (pos 1) not found

Edit:

self.myHandler.getEntry(0).getSurfacePoint(self.myHandler.getEntry(0).getIntoNodePath())

Right, you need to pass a parameter to getSurfacePoint(). This parameter is the NodePath in which you want the 3-d point expressed: due to the nature of the scene graph, each NodePath potentially represents a different coordinate space.

If you want global coordinates, use render.

David

What do you mean with:

When I use render, It can happen, that the point I clicked on is behind my char!?!?!?

A point (x, y, z) means something different in each NodePath. For instance, (0, 0, 0) to render is the center of the scene, but to your character, it might be the point right below his feet.

This is because each NodePath inherits the transform space of its parent, so the point (x, y, z) is relative to each NodePath’s parent transform.

This all means you need to think about what coordinate space you’re talking about whenever you speak of a position.

Usually, people who are not used to thinking about local coordinate spaces think always in terms of render, and that’s OK. It means your character is parented directly to render, and when you talk about your character’s position, you mean relative to render. Your terrain is also parented directly to render, and when you talk about a position on the terrain, you also mean relative to render. So probably render is the right NodePath to pass to getSurfacePoint(), unless you know that you’re dealing with some other coordinate space.

Whether that can return a point behind your character, I couldn’t tell you. That depends on the nature of your scene.

David