How can I set up multiple functions for a specific keybind depending on the situation?
Hey guys i have a little problem and i feel stupid about it. I hope someone have a better solution than mine
I work on a Historical / Simulation / Survivor game and i am stuck with the input.
Normally we set up InputComponent on a controller, pawn or character pair with the .ini to handle the key stroke and call functions but when it's active it's done we cannot do anything except redefine an another InputComponent to put it on top of the stack.
But imagine the situation where i would desable some key or change the purpose of a certain key depend on the situation or the state of game ie Leftclick for pick up object on normal mode and shoot or use the current equipment during combat mode.
I could probably go around and use raw data input but it could be cool if there is a better solution.
Thanks to help me
Well as far as i am concerned it is still the correct way... for what you are describing i would use a state-dependent Strategy-Pattern...
if you don't know the book "Design Patterns: Elements of Reusable Object-Oriented Software" yet, i highly recommend you read it before you go too deep into design decisions... It's like the bible of software architecture and computer games tend to have very complex architectures....
anyway i don't think you can leave the StateMachine-approach behind... I would design it with several global Player states like
and depending of your global state i would implement different strategies for UserActionRequest:Main
and the UserActionRequests-Events would be invoked by your InputManager which maps the KeyboardEvents to UserActionRequest-Events....
Or do you want to know how to write a parser for your config file and how to map the keyboard events to your game events depending on the config file?
I'm not quite sure if i understand it right but are you asking in a general way how to implement such a feature or if your implementation doesn't work... As a general software architecture answer: i would build a inputManager...
You build an inputManager based on a config file for your players input for example
The Manager has for each key you might use a Keyinput-Listener which Translates key inputs into "User Requests"
additionally to that you need a player StateMachine...
here is a simple one:
when Your Player is in the standing mode you can press jump or crouch and both actions will be executed... while you are jumping however any User Request will be ignored... and if you are crouching and request jump you get into ultra-jump mode...
so... i'm still not sure if i understood you wright and you are looking for basic concepts or how to implement them in code or if your code didn't work and you don't know why...
answered Apr 17 '14 at 08:02 AM
Hey there, I think I kinda got what you're saying. Basically, you want to be able to activate and deactivate KeyEvents (key pressed), right?
If so I found two ways: 1) Use Actor Blueprints within your Area and add an "enable input" e.G. if you overlap with a volume. Also make sure to disable the input if you leave the area (endoverlap or so). Then below simply add your key and what it should trigger. 2) Simply create a float variable in your player Blueprint. Set it up to 0 at first and then plug your keyEvent into a compareInt. Then decide what you want, for instance Value = 0 nothing happens, Value = 1 trigger something. Second step is to set the Value of that variable somewhere, like an actorblueprint that triggers a costum event in the players blueprint and then sets the value to 1 enabling the player to make use of the key-input event.
Hope that's what you were looking for. ;)
answered May 14 '14 at 05:07 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here