Simplest possible line of sight checking ... thoughts?
by David Janik-Jones · in Torque Game Builder · 09/17/2009 (12:51 pm) · 2 replies
What is the simplest method (pickLine?) to do the very minimal line of sight checking? A behaviour I can attach to a piece piece to check to see if any objects tagged "enemy" can be seen.
Example: Imagine a surface with 20 checkers on it ... 10 red ones (the player) and 10 blue ones (the AI). Never any more. All are currently in an "inactive" state right now. The player clicks on one of his red pieces an "activates" it ... meaning that he can now move it freely around the surface in some manner (drag, using arrow keys, perhaps clicking on a second point that then moves the piece there, etc).
As the piece is moving it does some form of pickLine check *only* to the 10 "enemy" pieces labeled "red" to see if it can be seen. If it becomes seen, the movement is interrupted/stopped (the piece becomes inactive again). The line of sight check is blocked by any type of obstacle item labeled "blocksLOS" but otherwise LOS can see any distance in a straight line.
I don't need fog of war or anything more complex than this. Am I on the right track thinking pickLine could do this assuming the player piece and all 10 other pieces could have their x,y positions made into a variable?
Example: Imagine a surface with 20 checkers on it ... 10 red ones (the player) and 10 blue ones (the AI). Never any more. All are currently in an "inactive" state right now. The player clicks on one of his red pieces an "activates" it ... meaning that he can now move it freely around the surface in some manner (drag, using arrow keys, perhaps clicking on a second point that then moves the piece there, etc).
As the piece is moving it does some form of pickLine check *only* to the 10 "enemy" pieces labeled "red" to see if it can be seen. If it becomes seen, the movement is interrupted/stopped (the piece becomes inactive again). The line of sight check is blocked by any type of obstacle item labeled "blocksLOS" but otherwise LOS can see any distance in a straight line.
I don't need fog of war or anything more complex than this. Am I on the right track thinking pickLine could do this assuming the player piece and all 10 other pieces could have their x,y positions made into a variable?
#2
09/17/2009 (2:48 pm)
Thanks for pointing out that excellent resource, Giuseppe! I don't immediately see how to use the tool to generate such code, but will research it after work today.
Torque Owner Giuseppe Bertone
DGform s.r.l.
you can start downloading the wonderful TGB Super Starter Kit. You'll find many pre-implemented math functions that can be a very good start to satisfy your needs.
In exemplum
/* Description: Returns true if %target is withing %fov angle of this object's 'forward vector' (facing). */ function t2dSceneObject::inFOV( %this, %target, %fov ) { ... }or
/* Description: Returns true if a vector drawn between this object and %target does not intersect any objects. Objects are ignored if they don't match the %groupMask. i.e. If they are not in any of the groups specified by that bitmask. */ function t2dSceneObject::inLOS( %this, %target, %groupsMask ) { ... }and many more.