Jump to content
Sign in to follow this  
RazorX

How to check if a unit can see another unit?

Recommended Posts

I.E. i want to return false (or a number) if the unit is covered behind a building or is behind the observer.

I'm currently using knowsAbout but it has some issues like the value still stays highest even if the unit has gone out of the field of view.

Any ideas?

Share this post


Link to post
Share on other sites

You'll have to create such a function yourself, but it's not something you run many times per second as it has a performance impact. Create an object and in a for loop move it from the observer to the target in x number of steps. If the objects position select 2 is more than intended, you have a ray intersect hit and you can exit the loop with "novisual".

Share this post


Link to post
Share on other sites

That's what I thought about, but the tricky part is, this must be executed on many units at the same time. Performance is crucial.

But there must be a built-in function for calculating the view of a unit - hell, the game would not work without it :P

Share this post


Link to post
Share on other sites

Give your units guns and put them on opposite sides. They'll shoot each other once they can see each other. Once you hear gunfire, you know they can see each other. ;)

Share this post


Link to post
Share on other sites
Give your units guns and put them on opposite sides. They'll shoot each other once they can see each other. Once you hear gunfire, you know they can see each other. ;)

Awesome, dude :D

Share this post


Link to post
Share on other sites

Sickboy suggested in another thread to use nearTargets and check for perceived position compared to actual position. So far this solution seems to work rather well for "can see" checks. It will of course think the target is not in LOS if it is too far or behind, not only if it is out of LOS, and might still think it's in LOS if target makes enough noise to get pinpointed. So it's not a true LOS check but it does tell if their group can see the target or not.

Share this post


Link to post
Share on other sites

Sounds like a good workaround to me. The context I used the approach I described first was to check if artillery could use a low angle trajectory without hitting anything.

Share this post


Link to post
Share on other sites

Works fine for groups of one.... but if the guy is the leader of a group of more than one..... it seems he will know about all the targets that the members of his group knows about....even after they are dead and buried!

Just today I had a group leader calling artillery on enemy he clearly could not see.... after the rest of his group was dead.

Using a nearestTargets list.... and then knowsAbout values of the targets in that list.

There should have been no targets in the list to get a knowsAbout from!

Edited by twirly

Share this post


Link to post
Share on other sites

Groups of the same side will share information silently.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×