samedi 11 janvier 2014

raycasting in puzzlescript

Another little technical issue I encountered was to determine whether player1 is visible by a soldier or not. After determining a set of obstacles occulting the view,  I came up with the following algorithm:


  • First, I pick a direction (say left), and, starting from the soldier, I mark every obstacle in the direction:


 LEFT [soldier |...| Obstacle no mark] -> [soldier |...| Obstacle mark]


  • Then, I do the same in the opposite direction, this time starting from the agent. If the ray encounters a marked obstacle, it means the obstacle is between the two players, and I mark the player as safe.


RIGHT [agent |...| Obstacle mark] -> [agent safe |...| Obstacle mark]


  • Finally I cast another ray from the soldier in the first direction, this time looking for the agent. If it is not marked as safe, it means it is visible, so I switch its state consequently.
LEFT [soldier | ... | agent no safe] -> [soldier | ... | agentvisible]


  • Before going on with the other directions I make sure to unmark the obstacles and the agent.

[mark] -> []
[safe] -> []

Aucun commentaire:

Enregistrer un commentaire