Is it possible to restrict a player's input so that they can only perform certain tasks?

I have a branch right now, however, that seems to be the problem. If “Close1” is activated, this allows the keypress to “kick” the ball. So if player 1 is close, there is nothing stopping player 2 from kicking the ball as well.

This is what I have now. It is SO close. Player 2 can still kick the ball, but it will now kick it in the direction that player 1 is facing… so player 2 is technically kicking the ball for player 1. Unfortunately though, player 2 can still kick the ball.

Hey guys! I am in need of help creating a system that restricts input on a player, but doesn’t completely get rid of it like the “Disable Input” node would. I need to restrict one action, but still allow the player to walk around. For example, I am creating a soccer game where the player has to be near the ball to kick it. I have recently figured out a way to return the player index and set a Boolean that lets the game know which player is close to the ball. As of now, I am setting a Boolean called “Close1” when player 1 is near the ball and “Close 2” when player 2 is near the ball. However, I have no way of disabling the “Kick” button for one player when the other player is near the ball, thus allowing player 2 to kick the ball if player 1 is near it. Would there be a way to disable the “Kick” button for each player until their Boolean, “Close1” or “Close 2”, is activated?

TLDR: I need the “Kick” button to be deactivated for each player until they get close to the ball.

Thanks so much!

Yes, simply dont bind the keys or dont use the key press events.

You could also put a branch at the key event to enable toggling.

In your case the boolean that dictates what execution branch is executed could be a check to see if the ball is closer than your threshold.

Then instead of having a boolean stored, simply store the name of the player and then check if the player that is pressing the kick key has the same name.

Additionally, I now have the problem that if both players are near the ball, the ball will always kick in the direction that player 1 is looking because the branch to see if player 1 is close happens to be first in the order of things.

You can either kick the ball that is the closest by comparing all players and selecting the closest one OR you can send in a vector from the player(or get it). Just use the players forward vector multiplied with the kick strength.

The way you are doing it it is impossible. Instead loop through all the players and save a reference to the closest one. Then you can use that reference inside the Kick ball 1(player 1) part.

This is what I have now… Its doing the same thing and allowing both players to kick it. Perhaps a screenshot of a setup that might work would help a lot, but if you do not have time I understand.

It is just that I am not in front of a PC with UE4 installed so I cant give you an example. Sorry.

The system you have now seems very complicated. In the first test you are already calculating who is closest so this allows us to ONLY let the closest player kick.

Then we need to differentiate between the players so if player 0 presses the kick button, then player 0 should kick the ball. That is the second branch. The third branch you do not need unless the kick button does something else if not close to a ball.

As far as I see this should work. The only thing that I would suggest changing is to try to migrate this to the ball and the player classes.

If you need more help I need a bigger screenshot and a description of what is happening and why that is not what you want.

Okay I’m sorry if this is getting a bit confusing, I’ve personally been trying to figure this problem out for nearly a year now and haven’t been able come up with anything. Below I have attached screenshots of everything that is going on with the kick. In the first screenshot, I am showing the actual kicking mechanics that are not working correctly.

In the second screenshot, I am showing the system that I am using to set the player distances from the ball. This system is working flawlessly and always allows me to see how far each player is from the ball at any given time.

The third screenshot is the system that handles collision with the ball and determining what player is near the ball at any given time. This is working flawlessly and will alert me when a player has approached the ball. This will then tell me which player is near the ball.

Now this all works well together, except for the fact that player two can kick the ball when player one is near. This occurs because, even though player 1 is the “close player”, player two can still send a “Kick”. So if player 1 is near the ball and player 2 kicks it…

  1. It will pass through the first branch because player 1 is closest to the ball.
  2. It will pass through the second branch because player 1 is in contact with the ball and is the “close player”
  3. It will pass through the third branch and continue on and add an impulse in the direction that player 1 is looking… Thus allowing player 2 to kick the ball “for” player 1 if player 1 is near the ball.

As you can imagine, this problem is reversible and allows player 1 to kick the ball for player 2 as well. If there was a way to determine which controller is sending the input, that would make this a very easy fix, however, as of now, I have not found that solution. I appreciate the help.

Wait, you are playing with two players locally on the same computer?

With the same keys?

That you can not do. You have to either change it to an online system OR give each player a different set of keys.

I am playing locally with two gamepads/ controllers. This is not normally a problem and has worked in other projects but this one never seems to want to work correctly. There is no way to check which gamepad pressed an input?

Then you have to create two player controllers and handle the input there. You can NOT do this in the level blueprint(I think).

Make two player controllers and they should pick up the controllers automagically. I cant remember how it works atm as it has been some time.