0
Answered

Toggle crouch on and off?

marjohloo 5 months ago in Game Creator updated by Marti (Lead Developer) 5 months ago 5
Unity version:
2018.4.21f
Game Creator version:
1.1.6
GOOD, I'M SATISFIED
Satisfaction mark by marjohloo 5 months ago

Oops forgot to ask my question I was so busy finding version info...

I followed the Crouch video on YouTube to crouch and move while holding a key. What I really want to do is press a key to toggle it on and off any suggestions?

At first I throught about making it a conditional on the Player's State, some thing like:

if (state == crouch) state = reset;

else                        state = crouch;

but it seems the conditional doesn't allow the state to be tested. In the comments on the video someone suggests looking at a patter conditional and refers to another video but no link. 


Do I need to add my own game creator variable to track the player state to do this sort of test and feed it back in or something else?

I should add that I'm a new unity and game creator user, but I am a C programmer in my work. Game Creator looks quite powerful but as a new user I'm thinking a few more videos for common stuff would be useful, especially for common gameplay elements like the above (and if I've missed the info somewhere apologies). As I get more into it I think it would be useful to have descriptions of what each control does in the panels and also where things have special meanings (wondering what consitutes a character's Is Busy conditional test actually checks). 

Answered

The Pattern Condition should work, as someone mentioned. The way it works is by letting you define a pattern. For example, the pattern [True, False] will return, every time the condition is checked in the following series: True, False, True, False, True, False, ...


This is perfect, since you want to toggle the crouch on and off. The way to do this is by making the Trigger "On key Down" call a Conditions object. This conditions should check the Pattern condition: "True, False".


Now, every time you press the crouch button, the condition will return true and false alternatively. All that's left to do is add the action that crouches the Player onto the Actions field in the Condition's clause and the action that makes the player stand up in the Condition's Else field.


Hope this helps!

OK I can see how that would work but if say we have key C to crouch toggle and D for drunk toggle (foir the sake of an example) from normal:

C goes normal to crouch

D goes crouch to drunk

C goes drunk to normal (because of the fixed T,F,T,F pattern)

So pattern doesn't really track the state (if there are multiple state to toggle on/off/between. So in this situation is my own variable best?

In that case, you'll need to create a Local Variable of type boolean and check against that value. When the character crouches, set the "crouch" variable to true and false otherwise. How complex you make this system really depends on how complex your game is. 


The solution I first mentioned is not all-in-one, but should work on most cases. If you want more fine grain control, a Local Variable would be best.