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

Arrow Key Movement / Camera System

Level 3
Joined
Oct 27, 2007
Messages
23
this has been done before but i didnt really like any of the others ons so i made one myself.

Arrow Key Movement

1.0
1) Create 3 Variables , named "Up", "Right" , "Left". Make those 3 boolean arrays for the type and make a new variable called Players_Hero with type Unit Array. and another variable named TempPoint and its type point array.

2) Create a map init trigger and set some unit into the Players_Hero variable

3) Create a new trigger named "Up Pressed"

4) add this event to the trigger : Player - Player 1 (Red) Presses the Up Arrow key

5) add the variable up in the actions part and make it look like this
Set Up[(Player number of (Triggering player))] = True

6) Make that for all the arrow keys exept for down.
Example:

  • ]Up Press
    • Events
      • Player - Player 1 (Red) Presses the Up Arrow key
      • Player - Player 2 (Blue) Presses the Up Arrow key
      • Player - Player 3 (Teal) Presses the Up Arrow key
      • Player - Player 4 (Purple) Presses the Up Arrow key
    • Conditions
    • Actions
      • Set Up[(Player number of (Triggering player))] = True
  • Right Press
    • 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
    • Conditions
    • Actions
      • Set Right[(Player number of (Triggering player))] = True
  • Left Press
    • Events
      • Player - Player 1 (Red) Presses the Left Arrow key
      • Player - Player 2 (Blue) Presses the Left Arrow key
      • Player - Player 3 (Teal) Presses the Left Arrow key
      • Player - Player 4 (Purple) Presses the Left Arrow key
    • Conditions
    • Actions
      • Set Left[(Player number of (Triggering player))] = True
1.1
Now we are going to create the "release triggers" you will basicly be doing the same thing as the pressed ones but like this
  • Up Release
    • Events
      • Player - Player 1 (Red) Releases the Up Arrow key
      • Player - Player 2 (Blue) Releases the Up Arrow key
      • Player - Player 3 (Teal) Releases the Up Arrow key
      • Player - Player 4 (Purple) Releases the Up Arrow key
    • Conditions
    • Actions
      • Set Up[(Player number of (Triggering player))] = False
      • Unit - Order PlayersHero[(Player number of (Triggering player))] to Stop
Now do that for all the arrow keys. exept dont add the Unit - Order Stop action in any of the other ones.

2.0
Create a new trigger named Movement. this trigger will be detecting the variables to order a unit to move. for example :
if the variable Up is = True then it will move that unit up.
1) create the event Time - Every 0.25 seconds of game time

2) add the action Player Group - Pick all players and do actions
Loop actions

3) in the loop actions part create an If/Then/Else action. so far it should look like this :
  • Untitled Trigger 001
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • Then - Actions
            • Else - Actions
in the If - Conditions part of the trigger add these conditions
  • Up[(Player number of (Picked player))] Equal to True
  • Left[(Player number of (Picked player))] Equal to False
  • Right[(Player number of (Picked player))] Equal to False
.

4) after that , create under the Then -Actions part the variable TempPoint like this
  • Set TempPoint[(Player number of (Picked player))] = (Position of PlayersHero[(Player number of (Picked player))])
after that action were going to add the moving part of it it should look like this
  • Unit - Order PlayersHero[(Player number of (Picked player))] to Move To (TempPoint[(Player number of (Picked player))] offset by 90.00 towards (Facing of PlayersHero[(Player number of (Picked player))]) degrees)
Now do the same thing in more loops for all the variables. it should look like this at the end :
  • Movement
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Up[(Player number of (Picked player))] Equal to True
              • Left[(Player number of (Picked player))] Equal to False
              • Right[(Player number of (Picked player))] Equal to False
            • Then - Actions
              • Set TempPoint[(Player number of (Picked player))] = (Position of PlayersHero[(Player number of (Picked player))])
              • Unit - Order PlayersHero[(Player number of (Picked player))] to Move To (TempPoint[(Player number of (Picked player))] offset by 90.00 towards (Facing of PlayersHero[(Player number of (Picked player))]) degrees)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Right[(Player number of (Picked player))] Equal to True
                • Then - Actions
                  • Set TempPoint[(Player number of (Picked player))] = (Position of PlayersHero[(Player number of (Picked player))])
                  • Unit - Order PlayersHero[(Player number of (Picked player))] to Move To (TempPoint[(Player number of (Picked player))] offset by 90.00 towards ((Facing of PlayersHero[(Player number of (Picked player))]) + -90.00) degrees)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Left[(Player number of (Picked player))] Equal to True
                    • Then - Actions
                      • Set TempPoint[(Player number of (Picked player))] = (Position of PlayersHero[(Player number of (Picked player))])
                      • Unit - Order PlayersHero[(Player number of (Picked player))] to Move To (TempPoint[(Player number of (Picked player))] offset by 90.00 towards ((Facing of PlayersHero[(Player number of (Picked player))]) + 90.00) degrees)
                    • Else - Actions
You're still not done. now for the diaganol movement part. we wont be actually ordering the unit to move diaganol we will move him instantly to point. this is pretty simple so im just going to post the trigger for diaganols.

  • Stop Turn
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Up[(Player number of (Picked player))] Equal to True
              • Left[(Player number of (Picked player))] Equal to True
            • Then - Actions
              • Unit - Make PlayersHero[(Player number of (Picked player))] face ((Facing of PlayersHero[(Player number of (Picked player))]) + 65.00) over 0.10 seconds
              • Set TempPoint[(Player number of (Picked player))] = ((Position of PlayersHero[(Player number of (Picked player))]) offset by 10.00 towards (Facing of PlayersHero[(Player number of (Picked player))]) degrees)
              • Unit - Move PlayersHero[(Player number of (Picked player))] instantly to TempPoint[(Player number of (Picked player))]
              • Animation - Play PlayersHero[(Player number of (Picked player))]'s walk animation
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Up[(Player number of (Picked player))] Equal to True
                  • Right[(Player number of (Picked player))] Equal to True
                • Then - Actions
                  • Unit - Make PlayersHero[(Player number of (Picked player))] face ((Facing of PlayersHero[(Player number of (Picked player))]) + -65.00) over 0.10 seconds
                  • Set TempPoint[(Player number of (Picked player))] = ((Position of PlayersHero[(Player number of (Picked player))]) offset by -10.00 towards (Facing of PlayersHero[(Player number of (Picked player))]) degrees)
                  • Unit - Move PlayersHero[(Player number of (Picked player))] instantly to TempPoint[(Player number of (Picked player))]
                  • Animation - Play PlayersHero[(Player number of (Picked player))]'s walk animation
                • Else - Actions
There you go you made an arrow key movement system. in case you didnt understand it or i didnt explain well take a look at the triggers your self in the demo map (Camera system is in demo map also). im pretty sure i spelled alot of things wrong so dont tell me about it. idk if im good or not at explaining things either soooo
 

Attachments

  • 187 Arrow Key Movement 1.1.w3x
    32 KB · Views: 3,213
Last edited by a moderator:
Level 40
Joined
Dec 14, 2005
Messages
10,532
I suggest replacing the
Code:
 tags with [trigger] tags, which are specifically built for GUI.

For the spoilers, you could use [plain][hidden=Spoiler](content)[/hidden][/plain], which would produce:

[hidden=Spoiler](content)[/hidden]

Also, Unit - Move Unit (Instantly) resets animations as far as I know, so that would look a little jumpy.
 
Level 2
Joined
Nov 19, 2007
Messages
8
Is [that] how button (hold) functions work? Hm. Need the pair of Press and Release event triggers.
Seems so obvious, and yet it never occurred to me before. Wonderful.
Not too keen on the rest of the code, but that's personal preference - easy to understand at least.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
would be better with JASS
hey dont look at me like that Im a Lamer
My job is causing annoying situations

Ups including much leaks too
 
Level 2
Joined
Jan 11, 2008
Messages
7
my opinion is do not try to make such a system

i made one for my rpg map, and the unit is walking awfully, it is like right clicking 4 times a seconds in front of the unit. Also if there is an obstacle in front of the unit, it won't go str8.

it's good however to show to people how to do this, even for practice, good work
 
Level 7
Joined
Dec 11, 2004
Messages
94
Its a nice way to make a movement system

Its a nice way to make a movement system, but I think iv created one much better for my new Heavy Combat 3 map in production, its similar to Heavy Combat 2's Movement system but a lot smoother and you can strafe.

I may release it in the spell area and as a tutorial after HC3 is complete.

UPDATE:

Oh, and WASD Movement is impossible. (or atleast GOOD WASD movement.)
 
Level 5
Joined
Dec 16, 2007
Messages
160
Does this make the unit move like a tank? Like.....

Up + Right = Turn right and move forward
Up + left = Turn left and move forward
Down + left = turn right while going backwards
Down + right = turn left while going backwards

If it is this is the exact thing i was looking for.
If not, Ill try making my own.
 
Level 3
Joined
Jul 18, 2008
Messages
53
Can u make W up S down D right and A left ? becous ther is a new tutorial called zoom in and rotating with arrow keys and in most rpgs Movement is on W A S D !
no

A is for attack
s is for stop

yes you can, you just change the hot keys from the attack and stop with whatever you want and then change the arrow keys with WASD keys. It's a video on youtube that a german made it but it has an error on the triggers.
 
Level 8
Joined
Jun 20, 2004
Messages
229
How can I make my hero turn faster like if I just tap the key instead of holding it for 1 second

arrow keys dont really work well with frequent pressing as it takes a little bit longer for it to recognize its being pressed compared to a traditional ability being casted when a hotkey is pressed. But you can simply just add an extra turning mechanism but place it on the triggers with the pressing events. Tapping would probably work without that if the periodic ran at .01 instead but probably is not needed for a third person view. It most definitely needed for a first person view as everything has to be as precise and exact as possible. And anyone who says using cameras that run at .01 is laggy and not needed is an idiot and has no clue what they are talking about. There is a miracle worker out there for maps based on keyboard detection and its called ListChecker. Simply start the map through LAN, then use the Bnet connection command and your hosting at LAN settings but people on Bnet can access it therefor when the map starts the delay is reduced by more than half.

if you are making a first person oriented camera control, then I would recommend doing away completely with the move to point command and use a sliding effect with index animations so you are not actually sliding and looks like a legit movement. WASD isnt impossible, but press and release detection is. Instead you have to improvise and be creative. Use the arrow keys to move forward, backward, and left and right to strafe and you have a very accurate FPS movement. Then use WASD to look left, right, up, and down by tapping them. It can feel very awkward at first but it is definitely the most efficient way without problematic trackables and quickly becomes easy to get the hang of if done correctly.
 
Level 7
Joined
Oct 8, 2008
Messages
200
Hmm would this arrow key system would be okay for like a game your hero is faces numerous number of enemies though? Like armies, gangs of heros etc
 
Level 5
Joined
Mar 14, 2009
Messages
34
lollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollollol
 
  • Angry
Reactions: Rui
There's a better way i already saw somewhere (on hive), because you can't play the units walk animation using gui --- you must use CustomScript
call SetUnitAnimationByIndex(udg_UNIT,X)
X = Animation number, not all units have the same number for the walk animation so you will have to find out which one it is.
udg_UNIT = UNIT is a variable (you can call it whatever), it plays the walk animation of the unit which is saved in the variable.
Next:
the Move Unit Instantly is also buggy (of course because it is GUI), use this:
1. Create 2 variables (for example tempX and tempY) type = Point
2. when the trigger runs (the one which moves the unit) save the point where the unit is going to move into the variables (X, Y)
  • Set tempX = (X of ((Position of UNIT) offset by SPEED towards (Facing of UNIT) degrees))
and
  • Set tempY = (Y of ((Position of UNIT) offset by SPEED towards (Facing of UNIT) degrees))
in this case SPEED is the amount of points the unit will move (i used acceleration which is a bit more harder to make, it only needs time) but for a normal movement speed use this: Unit_Speed/(1/Periodic time in the event)
its around 12 if the unit has a movement speed of 400 and the trigger runs every 0.03 seconds.
Then, after the position of the unit is saved into variables you have to use 2 custom scripts:
call SetUnitX( udg_UNIT, udg_tempX) ---> write there the name of the variable you used in my case it was tempX
call SetUnitY( udg_UNIT, udg_tempY) with this the same.

How can I make my hero turn faster like if I just tap the key instead of holding it for 1 second

You can add an action right into the trigger which runs the rotation.
  • Forward
    • Events
      • Player - Player 1 (Red) Presses the Right Arrow key
    • Conditions
    • Actions
      • Unit - Make UNIT face ((Facing of UNIT) - 30) over 0.10 seconds
 
Top