Checking direct line of sight with a NodePath

Hey !

I’d like to find out which NodePath are between a given object and the camera.
I tried setting CollisionRays starting from the model’s node to the camera’s node, but the ray always end up far higher than the actual camera.

I tried something of the likes:

{
  NodePath camera_node = GetCamera()->GetNodePath();
  NodePath character_node = GetPlayer()->GetNodePath();
  PT(CollisionRay) collision_ray;
  PT(CollisionNode) collision_node;
  NodePath collision_path;

  collision_ray = new CollisionRay();
  collision_node = new CollisionNode("");
  collision_node->add_solid(collision_ray);
  collision_path = window_framework->get_render().attach_new_node(collision_node);

  collision_path.set_pos(character_node.get_pos());
  collision_picker->set_origin(0, 0, 0);
  collision_picker->set_direction(camera_node.get_pos());

  collision_path.show();
}

I also tried setting the pos to 0,0,0 and the origin to the character_node’s position, but in this case I haven’t even been able to find where the ray ends up.

Is there a better solution for this problem ?

I think that the problem may lie in the direction that you’re using for your ray: you’re using the camera’s position, rather than the direction from the object to your camera. Try something like this, perhaps:

# Note the lack of the "set_origin" call; I don't think that it's called for.
collision_path.set_pos(character_node.get_pos());
collision_picker->set_direction(camera_node.get_pos() - character_node.get_pos());

That was it indeed ! Thank you !