x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

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!

Product Version: UE 4.10
Tags:
more ▼

asked Jul 28 '16 at 04:18 PM in Blueprint Scripting

avatar image

Anaklosmos
170 35 29 54

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jul 28 '16 at 04:39 PM

avatar image

NoobsDeSroobs
2.7k 106 34 177

avatar image Anaklosmos Jul 28 '16 at 04:45 PM

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.

avatar image NoobsDeSroobs Jul 28 '16 at 04:50 PM

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.

avatar image Anaklosmos Jul 28 '16 at 05:03 PM

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.

alt text

player.png (181.8 kB)
avatar image Anaklosmos Jul 28 '16 at 05:37 PM

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.

alt text

players.png (260.2 kB)
avatar image NoobsDeSroobs Jul 28 '16 at 05:44 PM

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.

avatar image Anaklosmos Jul 28 '16 at 06:19 PM

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.

alt text

lvl.png (243.9 kB)
avatar image NoobsDeSroobs Jul 28 '16 at 08:26 PM

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.

avatar image Anaklosmos Jul 30 '16 at 04:25 AM

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.

alt text

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.

alt text

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.

alt text

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.

1.png (247.4 kB)
2.png (108.0 kB)
3.png (184.7 kB)
avatar image NoobsDeSroobs Jul 30 '16 at 07:40 AM

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.

avatar image Anaklosmos Jul 30 '16 at 01:10 PM

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?

avatar image NoobsDeSroobs Jul 30 '16 at 06:22 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question