• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Disable Keyboard Scrolling

Status
Not open for further replies.
Level 7
Joined
Apr 12, 2009
Messages
188
As the title suggests. Is there any way to disable keyboard (left, right, up, down) scrolling WITHOUT locking the camera with triggers?

I read an old thread suggesting it was possible. That's here.

Basically I'm trying different ways of incorporating an adjustable camera into my game. My favorite way is the method i'm trying currently, that uses something like a 3rd person adjustable camera (using arrow keys to rotate and set AoA), but without locking the camera to a unit. It works beautifully! But... while you're adjusting your camera, you're also scrolling around the map :ugly:

If worse comes to worse I might have to settle for some kind of scroll lock while the keys are being pressed.
 
Level 7
Joined
Apr 12, 2009
Messages
188
Disable Keyboard Scrolling by locking the panning

So by locking the panning while a key is pressed, it makes it possible to disable keyboard scrolling. However this method is pretty sloppy and doesn't produce very smooth results. There's a really annoying lag between the time when you press a key, and the time in which the panning becomes locked, resulting in a certain amount of keyboard scrolling before the camera locks in place. I have no idea why this is, and if anybody else knows a better way to lock the panning than what I have done, please say!

  • Events
    • Time - Every 0.03 seconds of game time
  • Actions
    • For each (Integer A) from 1 to MaxPlayers, do (Actions)
      • Loop - Actions
        • Camera - Set (Player((Integer A)))'s camera Rotation to Rotation[(Integer A)] over 0.50 seconds
        • Camera - Set (Player((Integer A)))'s camera Angle of attack to AngleofAttack[(Integer A)] over 0.50 seconds
        • Camera - Set (Player((Integer A)))'s camera Distance to target to DistanceFromTarget[(Integer A)] over 0.50 seconds
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Or - Any (Conditions) are true
              • Conditions
                • RotateRight[(Integer A)] Equal to True
                • RotateLeft[(Integer A)] Equal to True
                • DoViewDown[(Integer A)] Equal to True
                • DoViewUp[(Integer A)] Equal to True
          • Then - Actions
            • -------- Lock the panning here, if a key is being pressed down. --------
            • Custom script: if GetLocalPlayer() == ConvertedPlayer(GetForLoopIndexA()) then
            • Set CameraRotLocX[(Integer A)] = (Target X of current camera view)
            • Set CameraRotLocY[(Integer A)] = (Target Y of current camera view)
            • Custom script: endif
            • Camera - Pan camera for (Player((Integer A))) to (Point(CameraRotLocX[(Integer A)], CameraRotLocY[(Integer A)])) over 0.00 seconds
          • Else - Actions
There are a ton more triggers that set up and update the variables Rotation, AngleofAttack, DistanceFromTarget, and the key press booleans every .03 seconds of game time for each player.



On the plus side, the above trigger is fully MUI and causes no problems when setting camera bounds (so long as you set the player's camera rotation to be 90 deg when doing so), re-orienting the camera (I think you are restricted to using panning durations of 0.00 s, but not sure), and it is easily disabled when desired. Thanks to The_Flood for writing most of the camera triggers in GUI that I copied/modified/observed to make this system work.


[EDIT] If instead of using the panning function in the above trigger you create a dummy unit whenever you press a key and lock the camera target to the dummy unit, then remove the dummy unit when no keys are being held down, it gets a little bit smoother, especially the transition between rotating the camera and quickly panning around with the mouse afterward. But there is still a lag between when you press the key and when the dummy unit gets created. Maybe there's a faster way of setting the location of the triggering player's camera target????
 
Last edited:
Level 7
Joined
Apr 12, 2009
Messages
188
Just detect if the players AOA (angle of attack) is not the default.
If it's not, just reset it.

Hmm I'm sorry but I have no idea what you're talking about : (


The AOA is updated for each player in the camera set trigger periodically ( every .03 seconds ) and is adjustable per the user by using the arrow keys. Resetting the AOA won't help anything : /
 
First of all, this one leaks:
  • (Point(CameraRotLocX[(Integer A)], CameraRotLocY[(Integer A)]))
Second of all, if the problem is the 'sloppiness', use
  • Camera - Set (Player((Integer A)))'s camera Angle of attack to AngleofAttack[(Integer A)] over 0.00 seconds
over 0.00 seconds, not 0.50 seconds. The first one is instant, while the second one adjusts the Angle of Attack within a period of 0.5 seconds.
 
Level 7
Joined
Apr 12, 2009
Messages
188
First of all, this one leaks:
  • (Point(CameraRotLocX[(Integer A)], CameraRotLocY[(Integer A)]))
I didn't know that! Thanks for pointing it out.

Second of all, if the problem is the 'sloppiness', use
  • Camera - Set (Player((Integer A)))'s camera Angle of attack to AngleofAttack[(Integer A)] over 0.00 seconds
over 0.00 seconds, not 0.50 seconds. The first one is instant, while the second one adjusts the Angle of Attack within a period of 0.5 seconds.

That's not really the problem. That 'over 0.5 seconds' bit actually adds a really cool smoothing effect. I think you'd have to try it to understand what I mean.

It's like when you press the arrow key, the event doesn't fire right away (or maybe it takes time to lock the camera to a unit/ begin to apply a pan), but the innate WC3 scrolling picks up instantly, so it takes a split second for the camera pan to lock in place, resulting in a small amount of scrolling before you start rotating. :ugly:

I'm actually rather happy with the way the system turned out, just that little delay is annoying.

EDIT: This is not the case. I think it has to do with the arrow keys having a lag when used to trigger an event, after doing some careful testing and observing.
 
Level 7
Joined
Apr 12, 2009
Messages
188
what kind of event do you use for your trigger

The triggers that activate/deactivate rotation look like this:
  • CameraPressRotateRight
    • Events
      • Player - Player 1 (Red) Presses the Right Arrow key
      • Player - Player 2 (Blue) Presses the Right Arrow key
      • Player - Player 3 (Teal) Presses the Right Arrow key
      • Player - Player 4 (Purple) Presses the Right Arrow key
    • Conditions
    • Actions
      • Unit - Remove CameraRotDummy[(Player number of (Triggering player))] from the game
      • Set RotateRight[(Player number of (Triggering player))] = True
      • Set RotateLeft[(Player number of (Triggering player))] = False
      • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
      • Set CamLoc = (Target of current camera view)
      • Custom script: endif
      • Unit - Create 1 CameraLocker for (Triggering player) at CamLoc facing Default building facing degrees
      • Set CameraRotDummy[(Player number of (Triggering player))] = (Last created unit)
      • Custom script: call RemoveLocation(udg_CamLoc)
  • CameraReleaseRotateRight
    • Events
      • Player - Player 1 (Red) Releases the Right Arrow key
      • Player - Player 2 (Blue) Releases the Right Arrow key
      • Player - Player 3 (Teal) Releases the Right Arrow key
      • Player - Player 4 (Purple) Releases the Right Arrow key
    • Conditions
    • Actions
      • Set RotateRight[(Player number of (Triggering player))] = False
This is the trigger that updates the rotation variable stored as an array.

  • SetCameraVariablesToRotation
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to MaxPlayers, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RotateRight[(Integer A)] Equal to True
            • Then - Actions
              • Set Rotation[(Integer A)] = (Rotation[(Integer A)] + 2.50)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Rotation[(Integer A)] Greater than 360.00
                • Then - Actions
                  • Set Rotation[(Integer A)] = 0.00
                • Else - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RotateLeft[(Integer A)] Equal to True
                • Then - Actions
                  • Set Rotation[(Integer A)] = (Rotation[(Integer A)] - 2.50)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Rotation[(Integer A)] Less than 0.00
                    • Then - Actions
                      • Set Rotation[(Integer A)] = 360.00
                    • Else - Actions
                • Else - Actions
So yeah, I'm using the key-press to trigger the event that locks the camera from panning by locking it to a unit.

Attached is quickie representation of the keystroke lag that I'm talking about. Pressing any of the arrow keys just pops up a message to you. You should notice visible delay between exactly when you press the arrow key, and when you see the message pop up.

Just for reference, this is the updated camera setting trigger with the new method of locking to a unit:
  • CameraSet
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to MaxPlayers, do (Actions)
        • Loop - Actions
          • Camera - Set (Player((Integer A)))'s camera Rotation to Rotation[(Integer A)] over 0.50 seconds
          • Camera - Set (Player((Integer A)))'s camera Angle of attack to AngleofAttack[(Integer A)] over 0.50 seconds
          • Camera - Set (Player((Integer A)))'s camera Distance to target to DistanceFromTarget[(Integer A)] over 0.50 seconds
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • RotateRight[(Integer A)] Equal to True
                  • RotateLeft[(Integer A)] Equal to True
                  • DoViewDown[(Integer A)] Equal to True
                  • DoViewUp[(Integer A)] Equal to True
            • Then - Actions
              • -------- Lock the panning here, if a key is being pressed down. --------
              • Camera - Lock camera target for (Player((Integer A))) to CameraRotDummy[(Integer A)], offset by (0.00, 0.00) using Default rotation
            • Else - Actions
              • Unit - Remove CameraRotDummy[(Integer A)] from the game
EDIT:

  • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
...caused desync. Don't do it that way.
 

Attachments

  • ARROW_KEY_LAG.w3x
    12.3 KB · Views: 86
Last edited:
Level 4
Joined
Apr 2, 2023
Messages
10
Sorry to Necro, but found an alternate solution future users might appreciate in the search results

If you create a cinematic camera, it prevents user from using arrow keys to move camera, or DEL to rotate. (pageUp/Down still zoom for some reason, unless I screwed up while testing).
An easy way to switch to cinematic mode without actually making a camera file is:
SetCameraRotateMode(0, 0, 0, 0)

Then, to allow user camera control again, leave cinematic mode like this:
StopCamera()
ResetToGameCamera(0)

As mentioned above, you can set individual settings, such as AoA (AngleOfAttack) to modify the zoom. But, there are a lot of settings to deal with, if instead you just want to backup/restore the current camera (including all camera fields at once), you can use these commands:
backupCamera = GetCurrentCameraSetup()
CameraSetupApply(backupCamera, false, false)

As was discussed earlier, if you wanted to prevent zoomIn/out, you could use the above backup/restore commands with a periodic timer trigger:
TriggerRegisterTimerEvent(myTrigger, .1, true)
 
Status
Not open for further replies.
Top