• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[TRIGGER] Check if camera sees your hero

Status
Not open for further replies.
Level 3
Joined
Mar 18, 2020
Messages
20
For constant checking or as an independent event?

The only way I can think of doing this would be creating an invisible flying dummy unit which is locked to the player's camera. ASFAIK there is no way to check for an edge pan with the mouse, but you could control the dummy with arrow keys to simulate camera controls. Alternatively you could make the dummy directly controllable by the player so you could move it to wherever you wish to view at a given time.

Then checking if a camera "sees" a hero would just be checking for distance from the position of the dummy camera unit. This could be very inconvenient depending on the size and style of your map, though.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,883
You can get the Camera Target Position X and Y. With that you can do something like:
  • Example
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Point = (Point((Target X of current camera view), (Target Y of current camera view)))
      • Region - Center CameraRegion on Point
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (CameraRegion contains Hero) Equal to True
        • Then - Actions
          • Game - Display to (All players) for 1.00 seconds the text: Hero is visible.
        • Else - Actions
      • Custom script: call RemoveLocation (udg_Point)
Now you'll notice that this doesn't allow you to specify a specific player's Camera. That's because this works like GetLocalPlayer.

Unfortunately i'm not too experienced with this stuff so my trigger probably causes desyncs in multiplayer. I imagine there's a safe way of going about it, i'm just not sure what it is. Maybe one of these guys know the proper way of handling this. @Pyrogasm @Dr Super Good
 

Attachments

  • Camera.w3m
    16.7 KB · Views: 22
Last edited:
Level 3
Joined
Mar 21, 2020
Messages
35
What's the scenario, when would you like to check if a hero is within camera bounds? Because you should avoid checking X variable every Y seconds.. it's bad for your map!
 
Level 3
Joined
Mar 21, 2020
Messages
35
So something like this:

  • YourTrigger
    • Events
      • *yourtriggerstuff*
    • Conditions
      • *yourtriggerstuff*
    • Actions
      • *yourtriggerstuff*
      • set triggeringPlayer = triggering player
      • set camBoundsRegion = current camera bounds
      • Trigger - Run CheckHeroCamBounds
  • CheckHeroCamBounds
    • Events
    • Conditions
    • Actions
      • set triggerUnitGroup = pick every unit owned by triggeringPlayer in camBoundsRegion
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Picked hero) is owned by triggeringPlayer
        • Then - Actions
          • Whatever you want to happen
        • Else - Actions
 
This system has what your looking for.

Advanced Camera, Keyboard & Movement System

The camera will never be obstructed by doodads as the camera will just move forward instead of going inside the doodad.

(Maybe a bit of recode and you can detect if your hero is obstructed/blocked by a doodad/object).

By the way you cannot open the map because it is saved in the current/post-reforged version of the editor, if you don't have interest updating your game to current version then (maybe) the only way you can open the map is by using World Editor of game version 1.31 since it is almost the same as the World Editor of post-Reforged patch(es).
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,883
@stan0033 The map contains that 1 trigger. The variables are Point, Unit, and Region. Fairly simple to recreate.

What's the scenario, when would you like to check if a hero is within camera bounds? Because you should avoid checking X variable every Y seconds.. it's bad for your map!
It obviously depends on what Stan wants to do in his map, but I want to note that it's perfectly fine to use periodic timers, it's how you use them that matters.

A timer that creates a point once every 0.10 seconds isn't going to hurt your performance. However, a timer that does something like "Pick every unit in playable map area' once every 0.10 seconds is another story. In the first case you're simply creating a point 10 times per second. In the second case you're looping through potentially 1000+ units, 10 times per second. 10 points vs 10,000 unit checks, you can guess which one will task your CPU more.

Now Event based systems are always better when possible, but in a lot of cases it's not possible or it's a much larger project to do so.

I'm not sure how the system @Strydhaizer posted works but I do know that it uses a Timer as well.

Here's a more Event based method that comes to mind (requires 1.31+):

Detect when a player presses the arrow keys along with using the new UI Frames to detect when a player's mouse is near the edge of the screen (moving the camera). Then in response to these Keyboard/Mouse Events you turn on a Timer that periodically checks the camera position like I did in the trigger I posted earlier. Once the player releases the arrow keys or moves their mouse away from the edge of the screen you pause the timer again. This way when the camera isn't moving the timer will be turned off.

Note that there may be a better way to detect if the camera is moving, this is just an idea I had.
 
What's the scenario, when would you like to check if a hero is within camera bounds? Because you should avoid checking X variable every Y seconds.. it's bad for your map!



Hey, I see many replies since my last visit. I was working on my map.

So, the idea is, whenever your hero is attacked, and your camera is not "seeing" him, to pan the camera to his position.

I used the idea of Uncle and it works well. I didn't notice any bugs with it so far...
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,883
Hey, I see many replies since my last visit. I was working on my map.

So, the idea is, whenever your hero is attacked, and your camera is not "seeing" him, to pan the camera to his position.

I used the idea of Uncle and it works well. I didn't notice any bugs with it so far...
That's perfectly fine as long as the map is singleplayer only. Edit: Otherwise, I believe it would desync.
 
That's perfectly fine as long as the map is singleplayer only. Edit: Otherwise, I believe it would desync.
It's 5-man multiplayer

the trigger does nto check every 0.10 secs but only when the heroes are attacked.

  • Pan Camera when Attacked
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Triggering unit) Equal to Hero[1]
          • (Triggering unit) Equal to Hero[2]
          • (Triggering unit) Equal to Hero[3]
          • (Triggering unit) Equal to Hero[4]
          • (Triggering unit) Equal to Hero[5]
    • Actions
      • Set CameraPos = (Point((Target X of current camera view), (Target Y of current camera view)))
      • Region - Center CameraView <gen> on CameraPos
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (CameraView <gen> contains (Position of Hero[(Player number of (Owner of (Attacked unit)))])) Equal to False
        • Then - Actions
          • Set HeroPanPos = (Position of (Attacked unit))
          • Camera - Pan camera for (Owner of (Attacked unit)) to HeroPanPos over 0.50 seconds
          • Custom script: call RemoveLocation(udg_HeroPanPos)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_CameraPos)
 
Last edited:
Oh, actually please disregard my previous suggestion, I misunderstood what you're asking.

I have a very similar system in my map, so I created a dummy unit at map initialization that's moving periodically every 0.03 at the target of the camera (the middle part of your screen) - you can create one dummy unit per player - and I periodically save the distance between the position of hero and the position of the dummy unit at the center of your current camera before the point is destroyed and the dummy unit is moved again. When the dummy unit is 2700+ in game distance away from the hero that means the hero is off the camera, in your case when your hero is attacked and the dummy unit is 2700+ distance away then pan the camera to the attacked hero.

(However I am not sure if this method will cause desyncs in multiplayer).
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,883
Looks like it should work in multiplayer.

It does leak a point though when you reference: Position of Hero[(Player number of (Owner of (Attacked unit))]. Instead you should set HeroPanPos outside of the If Then Else and then check if CameraView contains HeroPanPos.
 
Status
Not open for further replies.
Top