Hi, I'm trying to make a small waypoints guiding system for the NPCs in my game. I load some nodes called "waypoint" from the .irr file, save their positions, and I have a list with all the collidable objects in the scene, then I have a small algorithm to find the way form the NPC position to the player's position.
The problem is to check if the NPC has a clear path to the waypoint or the player.
I make this by building a line between both of them, and checking with the list of items if any of them are colliding with the line, the strange thing, is that the line collides with objects in a completely different place. I've checke that printing the name of the colliding item.
I have the feeling that the lines are being created with a different point of reference than the item's bounding box.
I know there are some already made libs for this, but it's for a college project, and making my own waypoint system will give me extra points...
Thanks in advance, and please tell me if I was not clear enough in my explanation.
Lines and Bounding Boxes problem
I send the absolute position of both characters as "pos1" and "pos2", "listProps" is the list of the collidable objetcs in the scene, and then check it this way:
Oh, I'm using IrrNewt for physics, does it have anything that can help me with this? I've checked everywhere but found nothing, thanks.
Code: Select all
core::line3df line;
core::vector3df start;
core::vector3df end;
start.set(pos1);
start.Y = 5;
end.set(pos2);
end.Y = 5;
line.setLine(start,end);
for(unsigned int k = 0; k < listProps.size(); k++){
if(listProps[k]->getBoundingBox().intersectsWithLine(line)){
printf("%s\n",listProps[k]->getName());
return false;
}
}
return true
Oh, I'm using IrrNewt for physics, does it have anything that can help me with this? I've checked everywhere but found nothing, thanks.
I suppose listProps contains ISceneNode's?
You probably want getTransformedBoundingBox instead of getBoundingBox. That will give you a boundingbox which regards the movement, translation and scaling of your scenenode which I suppose is what you want here.
You probably want getTransformedBoundingBox instead of getBoundingBox. That will give you a boundingbox which regards the movement, translation and scaling of your scenenode which I suppose is what you want here.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm