• 🏆 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!

Camera system problems - make the camera follow mouse x/y with a deadzone

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,554
Hello, I'm having trouble trying to get this trigger working. My goal is to have the camera lock to the player's hero, but with some additional options like allowing the camera to extend outwards when you move the mouse towards the edge of the screen. So I basically want a camera deadzone, check out this video for an example:


This trigger isn't finished and barely works but it may help in expressing what i'm trying to achieve. I have 2 dummy units, one is CameraDummy and the other is CameraDummyM. CameraDummy is always moving towards the player's mouse position and will eventually stop once it reaches the mouse position or gets too far away from the hero. During this i'm constantly checking to see if it has moved far enough away from the Hero that we can consider it be out of the "deadzone". Once it's out of the "deadzone" we can start moving the other dummy unit, CameraDummyM, towards the mouse. The player's camera is LOCKED to CameraDummyM, so this gives the effect of a deadzone. In other words, the camera (CameraDummyM) only moves once the mouse (CameraDummy) moves out of the deadzone-which let's say is a 600 radius around the hero.

Sorry if this is confusing, I may be going about this the completely wrong way. The problem with the simpler solutions like just "panning the camera" to the mouse x/y position is that it's extremely jittery and basically unplayable. Making the dummy's move with polar offsets allows for smooth movement. I can't have the camera instantly jumping far distances, it must feel smooth.

  • mouse timer
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • -------- points --------
      • Set heroPoint = (Position of PlayerHero[1])
      • Set mousePoint = (Point(mouseX, mouseY))
      • Set cameraPoint = (Position of CameraDummy)
      • Set cameraMPoint = (Position of CameraDummyM)
      • -------- distance/angles --------
      • Set distanceHeroToMouse = (Distance between heroPoint and mousePoint)
      • Set distanceHeroToCamera = (Distance between heroPoint and cameraPoint)
      • Set distanceHeroToCameraM = (Distance between heroPoint and cameraMPoint)
      • Set angleCameraToMouse = (Angle from cameraPoint to mousePoint)
      • Set angleCameraToHero = (Angle from cameraPoint to heroPoint)
      • -------- movement --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • distanceHeroToCamera Less than or equal to 600.00
        • Then - Actions
          • Set movePoint = (cameraPoint offset by 6.00 towards angleCameraToMouse degrees)
          • Set X = (X of movePoint)
          • Set Y = (Y of movePoint)
          • Custom script: call SetUnitX( udg_CameraDummy , udg_X )
          • Custom script: call SetUnitY( udg_CameraDummy , udg_Y )
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • distanceHeroToCamera Greater than or equal to 300.00
          • distanceHeroToCameraM Less than or equal to 300.00
        • Then - Actions
          • Set movePoint = (cameraMPoint offset by 6.00 towards angleCameraToMouse degrees)
          • Set X = (X of movePoint)
          • Set Y = (Y of movePoint)
          • Custom script: call SetUnitX( udg_CameraDummyM , udg_X )
          • Custom script: call SetUnitY( udg_CameraDummyM , udg_Y )
        • Else - Actions

The trigger needs a lot of work, but at the moment I can sort of mimic what i'm trying to achieve with it. I attached some pictures that may help. The camera is locked to the small blue orb, while the large blue orb is used to detect the deadzone. In picture 1 the camera hasn't moved because the mouse hasn't moved yet. In picture 2 the camera just started to move because the mouse has left the deadzone (the large blue orb represents your mouse position). In picture 3 the camera has extended out as far as it's allowed to go.

Questions/Issues:
1) How do I "leash" the camera dummy units so that they can't move beyond a certain distance from the hero?
2) How can I deal with the mouse position in regards to hovering over the user interface since this doesn't return a world x/y position?
3) If you know of a better method of going about this and could let me know it would be greatly appreciated.

Thanks for the help!
 

Attachments

  • 1.png
    1.png
    3.1 MB · Views: 65
  • 2.png
    2.png
    3.3 MB · Views: 95
  • 3.png
    3.png
    3.3 MB · Views: 58
Last edited:
Level 14
Joined
Jan 16, 2009
Messages
716
1) Check the distance periodically and if it's too far, move it back using trigonometry.
2) It will return (0,0) so you can catch that.
3) Lock the camera to a dummy, if the mouse is far enough start moving the dummy towards the mouse (until it reaches the maximum distance), if it's not then move the dummy towards the hero.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,554
Cool, thanks for the info. I have to admit I actually think I knew all of that already :p but it's nice reassurance to read that I was on the right track. Anyway, I realized that this system might not be worth it for my map so I'll probably put this on the backburner for now.
 
Status
Not open for further replies.
Top