• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Cone-Like Vision

Status
Not open for further replies.
Level 7
Joined
Jul 21, 2015
Messages
103
Hi everyone,
I'm trying to make my units have vision that is like a cone. I'm basing it off of the tutorial from here. Please look over my map and I imagine you might have to edit fields like field of vision in the object editor but honestly you might come up with your own mechanics.

I have also another request to make it so objects like trees and other large objects cannot be seen around to not be visible but this is highly complicated for me. My test map is attached if you want to see what I already have an altered from the tutorial.

In case you're not sure why I want this kind of vision is because humans have blind spots when they walk around so I'd prefer my map to have this aspect, so that the unit cannot see behind him but can see more ahead of him. I think it's a cool concept but also pretty impossible because of the lag it might create.
8.png


Thanks in advance that can help me out.
 

Attachments

  • Cone of Light.w3x
    19.4 KB · Views: 31
Level 39
Joined
Feb 27, 2007
Messages
4,989
I have also another request to make it so objects like trees and other large objects cannot be seen around to not be visible
I'm not sure wc3 can do light occlusion like that if you're using a custom light model as you would be doing here. Glad to be wrong if I am but I believe you can only get tuat arond terrain and destructables when using the normal DayNight models.
 
Level 9
Joined
Apr 23, 2011
Messages
527
I created something of this sort just for kicks as seen in this thread, however I did it inefficiently by using units instead of vision modifiers. I would follow the other posters' advice and modify the working trigger. If you don't have experience with modifying such triggers, you can ask other people to help.
 
Level 23
Joined
Jan 1, 2009
Messages
1,608
Well, think about the problem. The cone you are talking about is basically just a certain angle-range inside a circle around the unit.
I drew a small graphic to illustrate the 3 cases you have:
A: unit outside of circle range of guard
B: unit in range, but outside of cone
C: unit in range, and in cone

So all we have to do is exclude A and B from being seen.
qpxBeAO.png


To exclude A we use "pick all units in range from GUI:
  • Unit Group - Pick every unit in (Units within 256.00 of (Position of (Triggering unit))) and do (Actions)
Now we have B and C. In the image, the yellow line is the facing direction. If you calculate the angle from the guard to B and C, you can also calculate the difference to the guard's facing. If it is small enough, the unit is inside the cone.
  • Set angleToUnit = (Angle from (Position of (Triggering unit)) to (Position of (Picked unit)))
  • Set facingDifference = (Abs((angleToUnit - (Facing of (Triggering unit)))))
  • If (facingDifference Less than or equal to 30.00) then do (Custom script: unit is in cone)
This is basically the exact pendant to a "backstab detection".
If you have any questions about the triggers, let me know.
This also contains leaks which you have to handle later. I kept it should so you can understand the concept.
 
Level 39
Joined
Feb 27, 2007
Messages
4,989
@Frotty You forgot to modulo facingDifference, so it can fail without that. But more importantly the OP wants to place a light model in the direction that the unit (and thus human players) should be able to see, not just detect which other units shouldn't be seen by the central unit. Because what's the OP going to do if they know the unit shouldn't be able to see B or A? That information doesn't really help them. The problem isn't about detecting what should or shouldn't be seen, but where and how to place a light model (or light models) to simulate a conical field of view. The tutorial the OP linked to just puts a circular light model X distance in front of the facing of the unit, which kinda works but isn't very precise.
 
Level 7
Joined
Jul 21, 2015
Messages
103
Thanks everyone for ways on how to create such a thing, plus rep. Also I appreciate your other thread to a similar discussion Light.

I'm going to see if I can use what you guys posted into a working trigger.

EDIT: here is my progress so far (all I did was add more light models and mess around with their field of vision)

upload_2018-8-26_12-19-28.png


I tend to agree with @Pyrogasm that the mentioned triggers from @Frotty are not what would be applicable in this case but it would probably create a much smoother cone effect if I could use it to edit field of vision.
 

Attachments

  • Cone of Light.w3x
    21.1 KB · Views: 30
Last edited:
Level 7
Joined
Jul 21, 2015
Messages
103
A workaround is you could also "hide" units when not within vision range/angle.
Example:
Mini-Mapping Contest #14 - Stealth

If it's a multiplayer map, you can't use the hide function (ShowUnit(unit whichUnit, boolean flag)) because it will cause a desync. Instead you just have to make them transparent, hide hp bar and shadow and remove their footprints.
that is extremely interesting, I would love to see if I can get that working or a similar version
 
Level 23
Joined
Jan 1, 2009
Messages
1,608
@Frotty You forgot to modulo facingDifference, so it can fail without that.
Yeah, good catch. I didn't test this and forgot the angles can be negative.

But more importantly the OP wants to place a light model in the direction that the unit[...]

I didn't open the map but I think the description in the first post is quite ambiguous. You yourself mention, that doing it via fog and lights yields poor results.
And if the OP ever wants to see this cone vision through also for enemies and other stuff, a calculation like this is the only non trivial part imho.
 
Status
Not open for further replies.
Top