Path finding with bread crumbs - how to ray cast?
by Andy Hawkins · in Torque Game Builder · 12/03/2008 (4:33 am) · 2 replies
I want my NPCs to follow my player but when they go out of sight, the NPC relies on bread crumbs dropped to find the player (see pic)
However I need to cast a ray at the player and if it collides with a wall (or blocking object) the ray fails, and it keeps checking from the player back to all the bread crumbs dropped until it can find one that was most recently dropped that is in line of sight.
Question is: How do I cast a ray in TGB that reports if it fails by hitting something - it must know about tileLayers with collision tiles? How can I cast a ray in TGB to look for specific objects by id?
The only way I could think of was to make a fast moving projectile that collides with walls and reports if it's been stuck a second or two - therefore it hit something before hitting the object I was casting at - but I think this is just a hack.
Is there a better way?

However I need to cast a ray at the player and if it collides with a wall (or blocking object) the ray fails, and it keeps checking from the player back to all the bread crumbs dropped until it can find one that was most recently dropped that is in line of sight.
Question is: How do I cast a ray in TGB that reports if it fails by hitting something - it must know about tileLayers with collision tiles? How can I cast a ray in TGB to look for specific objects by id?
The only way I could think of was to make a fast moving projectile that collides with walls and reports if it's been stuck a second or two - therefore it hit something before hitting the object I was casting at - but I think this is just a hack.
Is there a better way?

Associate Phillip O'Shea
Violent Tulip
Anyway, to your question. Ray casting in TGB is called "picking". There are 4 types of picks:
To find out how to call them, check the documentation for t2dSceneGraph. Each of the functions will return a space separated list of object IDs which you will need to loop through to process.