LOS Question
by John Rush · in Torque Game Builder · 03/19/2005 (1:42 am) · 4 replies
I am working through my first T2D game and have found these forums very helpful. So thank you all for the help already.
For my current project, I have a sprite which is rotating and "chasing" the mouse pointer around the screen. My next step is to limit the players view of some of the other sprites (the enemies, actually) to only those that are within 60 degrees (or so) in the direction that the player is currently facing. I want to be able to hide sprites behind others, so I will need to analyze the order of sprites from the player outwards.
I think that pickRay() is the way to go here, but it still seems rather limiting. That is, the ray is only a line -- not a cone. My initial thought is to cast a ray every degree in the visible arc, but that may still break down over long distances across the screen (as the rays widen further away from the sprite). I can break it down even further to .5 degrees or even dynamically calculate how many degrees is needed to scan for a sprite of a given size at a given distance, but this seems excessive.
Are there other (better) ways of accomplishing this? I am still working through a lot of the documentation and forum posts, so it is very likely I missed something.
My plan is to show the entire enemy sprite if any part of the enemy is within the view cone, but let's for a moment assume that I only want to show that part of the sprite which is in the view cone. Is there a method I can use to clip a sprite in this way?
I have read other related posts here, and did not really find my answer. But if it is here somewhere already I appolize and perhaps someone will point it out to me.
For my current project, I have a sprite which is rotating and "chasing" the mouse pointer around the screen. My next step is to limit the players view of some of the other sprites (the enemies, actually) to only those that are within 60 degrees (or so) in the direction that the player is currently facing. I want to be able to hide sprites behind others, so I will need to analyze the order of sprites from the player outwards.
I think that pickRay() is the way to go here, but it still seems rather limiting. That is, the ray is only a line -- not a cone. My initial thought is to cast a ray every degree in the visible arc, but that may still break down over long distances across the screen (as the rays widen further away from the sprite). I can break it down even further to .5 degrees or even dynamically calculate how many degrees is needed to scan for a sprite of a given size at a given distance, but this seems excessive.
Are there other (better) ways of accomplishing this? I am still working through a lot of the documentation and forum posts, so it is very likely I missed something.
My plan is to show the entire enemy sprite if any part of the enemy is within the view cone, but let's for a moment assume that I only want to show that part of the sprite which is in the view cone. Is there a method I can use to clip a sprite in this way?
I have read other related posts here, and did not really find my answer. But if it is here somewhere already I appolize and perhaps someone will point it out to me.
#2
03/19/2005 (8:03 am)
How about mounting an invisible triangle sprite to the front of your player and using the collision system to detect what is in the field of view. You would also be able to get distances to feed into a z-sort if you are hiding enemies "behind" stuff.
#3
I decided to start by checking if the enemy within a 180 deg FOV. If so, and it is close enough, I will show it. Since the long-range FOV is less than 180, it seemed really strange to have items so close to the player that were not visible. So, now I show really close items if they are in the 180 FOV range.
Next, if they failed the above, I check to see if they are within the long-range FOV (I am using 90 deg because 60 seemed too narrow). This is done regardless of distance.
This is working nicely, but side-steps the feature of being able to hide behind things. I think a couple of you gave some good ideas on solving that problem, which I will try out soon.
I found this all feels kind of strange (now that I can playtest it), so I think I will try leaving objects out of the FOV grayed (or dimmed) in their last known location, so there is not so much flickering on/off as the player moves. I have a couple of ideas to accomplish that.
Thanks again for the help.
03/19/2005 (2:16 pm)
Thanks, everyone.I decided to start by checking if the enemy within a 180 deg FOV. If so, and it is close enough, I will show it. Since the long-range FOV is less than 180, it seemed really strange to have items so close to the player that were not visible. So, now I show really close items if they are in the 180 FOV range.
Next, if they failed the above, I check to see if they are within the long-range FOV (I am using 90 deg because 60 seemed too narrow). This is done regardless of distance.
This is working nicely, but side-steps the feature of being able to hide behind things. I think a couple of you gave some good ideas on solving that problem, which I will try out soon.
I found this all feels kind of strange (now that I can playtest it), so I think I will try leaving objects out of the FOV grayed (or dimmed) in their last known location, so there is not so much flickering on/off as the player moves. I have a couple of ideas to accomplish that.
Thanks again for the help.
#4
This is an interesting problem. Just to let you know, I've added to my NICETO list, the ability to specify a polygon region to pick from. Not sure when it'll get done but it is an interesting idea. This may end up being the trigger-zone object that is also on the list which you could use as a LOS region.
Just thought I'd let you know.
- Melv.
03/21/2005 (2:48 am)
John,This is an interesting problem. Just to let you know, I've added to my NICETO list, the ability to specify a polygon region to pick from. Not sure when it'll get done but it is an interesting idea. This may end up being the trigger-zone object that is also on the list which you could use as a LOS region.
Just thought I'd let you know.
- Melv.
Torque Owner Gary Preston
The first is to determine whether an enemy is possibly in sight, which means it has to be within 60deg. So using a bit of vector math for each enemy work out whether its within a 90deg view (that is more efficient than calculating the exact angle). Any that are not can be ignored straight away. Any that are, need the final part of the calculation to get the exact angle. If its less than 60deg, then the sprite MAY be visible, but still may not, so onto stage two.
Cast a ray from the enemy to the player. If it hits the player, its in view. If it hits another object on the way first, then its blocked. You may need two rays, one either side of the object just incase your sprite is half poking round a wall or something similar.
I imagine there are many better ways than this, but it might get you going :) Also this could be optimised in a number of ways. In 3d games people used portals to split up visible areas, I'm sure a similar and much simpler system could be made in 2d.