Ah, I see why its not working.
When up key pressed, It appears this is what was done.
Quote:
Vertical = 1;
Change it to
Quote:
Vertical = Vertical + 1;
When down is pressed,
Quote:
Vertical = Vertical - 1;
This way, if up and down are both pressed, vertical will equate to 0, thus indicating no movement on the Y-axis.
When the up key is released, you will also need to make sure you do:
Quote:
Vertical = Vertical - 1;
So that vertical will equate to -1, indicating the down key is still pressed.
Fix this for the horizontal (x-axis) as well and it should work.
The default value for both Vertical and Horizontal are 0. So if Vertical + Horizonal = 0, Disable the move trigger so you don't burn up unnecessary processor power, causing latency.
I'm currently doing some experimentation with the arrow keys as well. For some annoying reason, it doesn't register all the key actions. If too many keys are hit, it only catches say 3 of 4 of the keystrokes, and ignores one of them. This can lead to the key press flags getting stuck and screwing up the code.
Anyway, could you perhaps post a screenshot of your code? Would be easier for someone to step up and help that way. I'll get back to you tommorrow.. Its 2am here so i really gota get to bed.. =/
If you're looking for alternatives, you might want to take a look at progammers data only WASD move system tutorial/library?
Heres the rough pseudocode for what you're trying to do.
Use an two array's with 8-10 spaces to store the arrow states.
int[8] vert;
int[8] horz;
Initialize them to 0 to represent no button presses.
Event: Any player presses arrow key:
For the Triggering Player.
If Up pressed, vert + 1
If Down Pressed, vert - 1
If Left Pressed, horz - 1
If Right Pressed, horz + 1
Do the opposite if the buttons are released.
If both vert and horz for the player are not zero.
Enable the movement trigger for the player, using either move instantly or order unit to move to location.
Use the vert and horz integer states to calculate the direction you should be moving.
Example: vert = 1, horz = 1, Indicates the unit should move upwards towards the right.
Try to find a trigonometric formula that maps all these states to make it easier. I'm too tired to think of it right now, so good luck. :P
else Disable the movement trigger to save processing power.
The movement trigger should run with a periodic event. With an interval of maybe 0.05, depending on how smooth you want the movement to be.
Sorry bout the bullet point spam. The posting system is gonna ignore all my nextline chars if i don't use them.
Edit: Warning though.. You're gona have to wait til pattch 1.2 comes out before Blizzard fixes the key lag issue. Also, if you're trying to program movement that traces the mouse.. Wait til 1.2, Its pretty hard to do mouse tracking as it is now.
@Ivono: Go
Ah, I see why its not working. When up key pressed, It appears this is what was done.
Change it to
When down is pressed,
This way, if up and down are both pressed, vertical will equate to 0, thus indicating no movement on the Y-axis.
When the up key is released, you will also need to make sure you do:
So that vertical will equate to -1, indicating the down key is still pressed.
Fix this for the horizontal (x-axis) as well and it should work. The default value for both Vertical and Horizontal are 0. So if Vertical + Horizonal = 0, Disable the move trigger so you don't burn up unnecessary processor power, causing latency.
@Ivono: Go
I'm currently doing some experimentation with the arrow keys as well. For some annoying reason, it doesn't register all the key actions. If too many keys are hit, it only catches say 3 of 4 of the keystrokes, and ignores one of them. This can lead to the key press flags getting stuck and screwing up the code.
Anyway, could you perhaps post a screenshot of your code? Would be easier for someone to step up and help that way. I'll get back to you tommorrow.. Its 2am here so i really gota get to bed.. =/
If you're looking for alternatives, you might want to take a look at progammers data only WASD move system tutorial/library?
@Ivono: Go
Heres the rough pseudocode for what you're trying to do.
Use an two array's with 8-10 spaces to store the arrow states.
int[8] vert; int[8] horz;
Initialize them to 0 to represent no button presses.
If both vert and horz for the player are not zero.
The movement trigger should run with a periodic event. With an interval of maybe 0.05, depending on how smooth you want the movement to be.
Sorry bout the bullet point spam. The posting system is gonna ignore all my nextline chars if i don't use them.
Edit: Warning though.. You're gona have to wait til pattch 1.2 comes out before Blizzard fixes the key lag issue. Also, if you're trying to program movement that traces the mouse.. Wait til 1.2, Its pretty hard to do mouse tracking as it is now.