HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Using the Arrow Keys to Move

11-20-2005, 03:14 PM#1
Nebu_Bei
Could anyone tell me how to make a trigger(s) that would allow me to move my hero with the arrow keys?
11-20-2005, 05:17 PM#2
Thunder_Eye
I have that kind of trigger somewhere.. I could look it up if you want.
11-20-2005, 06:28 PM#3
tassadar920
You have to have four triggers, each with the event that checks the keyboard, I forgot the exact name but it's pretty obvious.

Anyways, when they press "down" on the up key you will want to order the unit to move to a point all the way across the map, directly forward from them, when they release it you tell them to stop. If you want people to be able to walk in reverse it gets very complicated, so I recommend not bothering with that.

For the turning it's a little more complicated, I would recommend making a trigger that is periodic, maybe 5 times a second or so it changes orientation +1 degree, you need a second trigger for -1 degree (left turn). Set both to be initially off. Then make 4 triggers, two that when the key is pressed the trigger turns on the periodic event (and also turns slightly right away otherwise you get a "delay" on turning) and two more that turn both periodic triggers off.

Hopefully that made sense.
11-20-2005, 07:05 PM#4
Nebu_Bei
I think I got it. Thanks.
12-19-2005, 12:59 PM#5
qwertyui
Last time i checked, there was no trigger that captured key releases.

But then again, last time i checked it was quite some years ago :)
12-19-2005, 01:10 PM#6
Zoxc
The unit variable: commonunit is the unit you are controlling.
real, camerarotation: is how the camera is turn.
integer, array Movement is what keys that are pressed.

GetCommonUnit returns commonunit.

You go forward/backwards with Up/Down. Rotates the camera with Left/Right.

The unit animation is flickering thus...

Custom Script:
Collapse JASS:
function CameraFields takes nothing returns nothing
call SetCameraFieldForPlayer(Player(0),CAMERA_FIELD_TARGET_DISTANCE,570,0)
call SetCameraFieldForPlayer(Player(0),CAMERA_FIELD_ANGLE_OF_ATTACK,320,.50)
call SetCameraFieldForPlayer(Player(0),CAMERA_FIELD_FIELD_OF_VIEW,860,0)
call SetCameraFieldForPlayer(Player(0),CAMERA_FIELD_ZOFFSET,105,0)
endfunction

function GetCommonUnit takes nothing returns unit
    return udg_commonunit
endfunction

Trigger:
Init
Collapse Events
Time - Elapsed game time is 0.01 seconds
Conditions
Collapse Actions
Custom script: call CameraFields()
Set camerarotation = (Facing of commonunit)

Trigger:
Update camera
Collapse Events
Time - Every 0.07 seconds of game time
Conditions
Collapse Actions
-------- Movement --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Movement[0] Equal to True
Collapse Then - Actions
Set camerarotation = (camerarotation + 10.00)
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Movement[1] Equal to True
Collapse Then - Actions
Set camerarotation = (camerarotation - 10.00)
Else - Actions
-------- 0-360 limit --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
camerarotation Less than 0.00
Collapse Then - Actions
Set camerarotation = 360.00
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
camerarotation Greater than 360.00
Collapse Then - Actions
Set camerarotation = 0.00
Else - Actions
-------- Rotation --------
Camera - Set Player 1 (Red)'s camera Rotation to camerarotation over 0.15 seconds
Camera - Lock camera target for Player 1 (Red) to (GetCommonUnit()), offset by (0.00, 0.00) using The unit's rotation
Camera - Change camera smoothing factor to 0.00
Custom script: call CameraFields()

Trigger:
Update movement
Collapse Events
Time - Every 0.20 seconds of game time
Conditions
Collapse Actions
Custom script: local location up = GetUnitLoc(GetCommonUnit())
Custom script: local location ud
-------- Movement --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Movement[2] Equal to True
Collapse Then - Actions
Custom script: set ud = PolarProjectionBJ(up, 100.00, udg_camerarotation)
Custom script: call IssuePointOrderLoc( GetCommonUnit(), "move", ud )
Custom script: call RemoveLocation(ud)
Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Movement[3] Equal to True
Collapse Then - Actions
Custom script: set ud = PolarProjectionBJ(up, 0-100.00, udg_camerarotation)
Custom script: call IssuePointOrderLoc( GetCommonUnit(), "move", ud )
Custom script: call RemoveLocation(ud)
Else - Actions
Custom script: call RemoveLocation(up)
Custom script: set up = null
Custom script: set ud = null

Trigger:
Right Up
Collapse Events
Player - Player 1 (Red) Releases the Right Arrow key
Conditions
Collapse Actions
Set Movement[1] = False
Trigger:
Right Down
Collapse Events
Player - Player 1 (Red) Presses the Right Arrow key
Conditions
Collapse Actions
Set Movement[1] = True
Trigger:
Left Up
Collapse Events
Player - Player 1 (Red) Presses the Left Arrow key
Conditions
Collapse Actions
Set Movement[0] = True
Trigger:
Left Down
Collapse Events
Player - Player 1 (Red) Releases the Left Arrow key
Conditions
Collapse Actions
Set Movement[0] = False
Trigger:
Up Up
Collapse Events
Player - Player 1 (Red) Presses the Up Arrow key
Conditions
Collapse Actions
Set Movement[2] = True
Trigger:
Up Down
Collapse Events
Player - Player 1 (Red) Releases the Up Arrow key
Conditions
Collapse Actions
Set Movement[2] = False
Trigger:
Down Down
Collapse Events
Player - Player 1 (Red) Releases the Down Arrow key
Conditions
Collapse Actions
Set Movement[3] = False
Trigger:
Down Up
Collapse Events
Player - Player 1 (Red) Presses the Down Arrow key
Conditions
Collapse Actions
Set Movement[3] = True
12-19-2005, 02:05 PM#7
qwertyui
Last time i tinkered with this i ran into this problem:

U is unit.
| is wall
_ is empty space

suppose its like this:

U___|

You tell the unit to move right, and he does so:
_U_|
And then so:
__U|
But when he comes up against a wall he suddenly has to path around it, so it becomes something like this:
__U_
___|

I couldn't find where this problem is adressed in that code you posted
12-19-2005, 02:48 PM#8
Zoxc
Hopefulle he isn't ordered to go over the center of the object. He stays on his side of wall.
12-19-2005, 02:56 PM#9
qwertyui
Well, then you would have to constantly re-issue movement orders, because you would be giving them over relatively small distances.

As a result, the unit's movement animation becomes incredibly twitchy, constantly replaying a "movement start" part over and over again.


Well, at least it was like this back in 2004 when i tinkered with it :)

Also, there are some very thin walls out there. e.g. fences.
12-19-2005, 02:57 PM#10
iNfraNe
hmm, ordering is bad for this. SetUnitX/Y works like a charm with custom pathing checks
12-19-2005, 03:02 PM#11
Zoxc
I really worked hard on this you know :P
12-19-2005, 03:17 PM#12
qwertyui
Yeah,
I worked on it for days back there, and still couldn't find any solution.

Well, actually i did. That solution is in 3 steps:
1) making the player-controlled unit ignore normal wc3 pathing
2) issue movement orders to the edges of the map, not to 100 units forward
3) draw up "restricted regions" and forcing hero to stop moving every time he attempts entering those

This will still work sucky when you want your hero to be able to move in 360 degrees. But i expect this to work fine when hero is moving in 8 directions only :/

I never implemented it though, since its simply too much work over an imperfect system. wc3 was never meant for keyboard control :(
12-19-2005, 03:42 PM#13
Anitarf
Actually, you can make quite nice systems, the problem is the lag. The netwok code just wasn't meant for action games. Even games that are played with a mouse, but require manual weapon aiming or stuff like that, are hard to play when you're not host.
04-06-2006, 12:38 AM#14
Jarock
Zoxc what is Movement [1], [2], [3] comeing from? It can't be a variable because it doesn't alow me to insert "[" or "]". If you would know where the movement stuff is comeing from it could help.
04-06-2006, 05:01 PM#15
Vexorian
It is an array

And this thread is quite old