HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help with Unit Turning Triggers

10-03-2007, 04:03 AM#1
Salbrismind
I'm trying to make a trigger set that makes a unit rotate to the left or right only when the left or right key is pressed and stops when the key is released. After trying to figure this out for about 2 hours i've given up and i need help.

This is the Left Press Trigger:
Trigger:
Turn left
Collapse Events
Player - Player 1 (Red) Presses the Left Arrow key
Conditions
Collapse Actions
Collapse For each (Integer leftloop) from 1 to leftmax, do (Actions)
Collapse Loop - Actions
Unit - Make Flyer 0000 <gen> face ((Facing of Flyer 0000 <gen>) + 5.00) over 0.00 seconds
Wait 0.01 seconds
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
leftloop Greater than 0
Collapse Then - Actions
Set leftmax = (leftmax + 1)
Else - Actions

This is what i thought should stop it:

Trigger:
Cancel left
Collapse Events
Player - Player 1 (Red) Releases the Left Arrow key
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 10, do (Actions)
Collapse Loop - Actions
Set leftloop = 0

I've tried many variation of this idea such as an if within the press trigger that if leftloop is 0 it does not let the rest occur.

Also even if it were to work it isn't very smooth because the unit looks like it's jiggling as it rotates.

Check it out: Movement Test.w3x

Thanks for any help, this is critical for my map to work well.
10-03-2007, 08:07 PM#2
Anopob
What's wrong (didn't check test map yet)? Just wondering, but what's the wait for? And what's the default for leftmax? If it's 0, and your turning doesn't work, maybe set it to something higher for your loop.
10-03-2007, 08:50 PM#3
wyrmlord
Quote:
Originally Posted by Salbrismind
I'm trying to make a trigger set that makes a unit rotate to the left or right only when the left or right key is pressed and stops when the key is released. After trying to figure this out for about 2 hours i've given up and i need help.

This is the Left Press Trigger:
Trigger:
Turn left
Collapse Events
Player - Player 1 (Red) Presses the Left Arrow key
Conditions
Collapse Actions
Collapse For each (Integer leftloop) from 1 to leftmax, do (Actions)
Collapse Loop - Actions
Unit - Make Flyer 0000 <gen> face ((Facing of Flyer 0000 <gen>) + 5.00) over 0.00 seconds
Wait 0.01 seconds
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
leftloop Greater than 0
Collapse Then - Actions
Set leftmax = (leftmax + 1)
Else - Actions

This is what i thought should stop it:

Trigger:
Cancel left
Collapse Events
Player - Player 1 (Red) Releases the Left Arrow key
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 10, do (Actions)
Collapse Loop - Actions
Set leftloop = 0

I've tried many variation of this idea such as an if within the press trigger that if leftloop is 0 it does not let the rest occur.

Also even if it were to work it isn't very smooth because the unit looks like it's jiggling as it rotates.

Check it out: Attachment 29402

Thanks for any help, this is critical for my map to work well.

Instead of what you're doing, I'd suggest having a global boolean variable set to true when the key is pressed and set to false when it's released. Then, you can have a separate periodic trigger that would run every .03 seconds or whatever suits your needs. This trigger would check to see if the boolean variable was true and if so, rotate the unit. Otherwise, it would just let things be.
Attached Files
File type: w3xMovement Test.w3x (17.6 KB)
10-04-2007, 02:21 AM#4
Salbrismind
Update: I fixed it with your idea and with one little fix to it, it works perfectly and smoothly. Thanks a lot. + rep!

Original:
Quote:
Originally Posted by wyrmlord
Instead of what you're doing, I'd suggest having a global boolean variable set to true when the key is pressed and set to false when it's released. Then, you can have a separate periodic trigger that would run every .03 seconds or whatever suits your needs. This trigger would check to see if the boolean variable was true and if so, rotate the unit. Otherwise, it would just let things be.

Well first i'll say i did fix the problems i had last night. For some reason i'm not as smart when i do map making at night but thanks for the suggestion as it might fix the various bugs my new system has. For no apparent reason when i constantly tap the left or right it starts to rotate non-stop until i press the key again. Here's the new code:
Trigger:
Turn left
Collapse Events
Player - Player 1 (Red) Presses the Left Arrow key
Conditions
Collapse Actions
Set leftmax = 1
Collapse For each (Integer leftloop) from 1 to leftmax, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
leftcheck Not equal to 0
Collapse Then - Actions
Unit - Make Flyer 0000 <gen> face ((Facing of Flyer 0000 <gen>) + 30.00) over 0.00 seconds
Wait 0.01 seconds
Set leftmax = (leftmax + 1)
Else - Actions

Trigger:
Cancel left
Collapse Events
Player - Player 1 (Red) Releases the Left Arrow key
Conditions
Collapse Actions
Set leftcheck = 0
Wait 0.10 game-time seconds
Set leftcheck = 1

I'm gonna try your separate trigger idea, it might just do the trick. The only problem i foresee is the lag that could happen when i have 8 of these running at once (8 players in full version). Any ideas?
10-04-2007, 02:46 AM#5
Anopob
I think the wait is too short (in trigger 2) or because every time you press the left key it goes to leftmax = 1, meaning it keep turning if you tap it.
10-04-2007, 03:31 AM#6
Salbrismind
Quote:
Originally Posted by Anopob
I think the wait is too short (in trigger 2) or because every time you press the left key it goes to leftmax = 1, meaning it keep turning if you tap it.

Note: I said i fixed XD, but still, it would continue to rotate even if i didn't tap it. I think it was because i hit it before it could set check to 0 so it would never stop even though the key is not pressed.