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"

How do you set up a player controller that is able to control player player controllers?

I'm trying to set up movement for what I thought would be a very simple game, but I'm being bamboozled by how the player controller works. I need to have two pawns that can be controlled independently from one and other. These are going to be controlled by the same player locally and need to contribute to the same score. From all the stuff I have read the best way of doing this is by setting up a master player controller which is what the player controls. This acts like a brain for two other player controllers which each posses their own pawn. I feel like this is the ideal way of doing this as the master controller's player state is what it going to hold the score. Right now this I'm trying to get this to work for local single player game mode but once I've got this nailed down there are plans to get have both networked and local multiplayer which is another reason why I feel the need to have a master player controller for each player which then controls pawns that will be spawned in as and when they are needed.

TLDR: How do I use inputs registered in the master controller to run scripts in sub player controllers that each posses their own pawn.

This is how I think the set up should got but I have no idea if my understanding of how player controllers work. alt text

I've managed to set up something that mimics the effect that I am looking for by having one actor take in inputs that control the movement of two separate meshes within the actor. I couldn't make a GIF that was under the upload limit so here is a YouTube showing what it should look like.

I found a post on here that was wither looking for something similar or the exact same thing that I am after. So I added their blueprint to my game mode and it looks like this. the game mode is set up so the master controller is the default and Pawn1a is the default pawn class.

alt text

When I use this code on all three of the player controllers they all print "-1" which makes me think that they are all connected somehow, but I also thought they should be printing 0, unless the value isn't the player index and I've got that wrong.

Edit: I figure out that I wasn't using setting or getting player controller, which is why it was returning -1 instead of 0. alt text

If this is working as intended right then "YAY". However I don't know how to pass information between the blueprints in order to control the pawns. This is where I am stuck. How do I set up a script in the master controller that is able to take action events as inputs and use that to fire off scrips that control the movement of each pawn? If it helps currently I have a script that finds the closest This is currently attached to the pawn itself but I suspect I need to attach it to the respective sub player controllers and make the pawn move along with the controller??? Anyway thanks for reading this far. If you have any thought or suggestions they would be greatly appropriated. Also here is a Google Drive link with the source files so far, which is 22.5 mb unzipped.

Product Version: UE 4.15
Tags:
dsc-0131-1.jpg (1.6 MB)
spawn.jpg (113.0 kB)
pawnfunction.jpg (107.2 kB)
more ▼

asked May 08 '18 at 12:33 PM in Blueprint Scripting

avatar image

Alunnite
1 1 2

avatar image ThompsonN13 May 08 '18 at 02:34 PM

what exactly are you trying to implement gameplay wise? like what functions, movement? whats the camera setup? you shouldnt ever need more than one player controller for each player to my knowledge so theres probably an alternative method to accomplish what your looking to do.

also your video is useless, its so low rex thats its hard to make out whats happening.

avatar image Alunnite May 08 '18 at 04:50 PM

I've made a better video now and edited the link.

I'm trying to make a simple score attack game mode at the moment. So the player has control of one pawn and can move it in the four directions. Directing it to a pickup when the pawn overlaps the target moves to a new position within a grid and the player gets a point. The player's goal is to hit X number of points before a timer hits 0. If they hit the score target before the points hit zero then they move onto the next round with a timer reset and a the score target is increased by a number. Eventually the player will be given a second pawn which they will control independently and will have it's own pickup. Difficulty increases as the rounds increase. It's kind of hard to play when your right hand is trying to control the left most pawn - that's the real gimmick.

In the video I had input, movement, scoring, and camera setup within one actor. Meshes were used to move the mesh by 200 units up down left or right, as the poles are just there for visual representation. They also don't align in the video because of some messing around I didn't fix. Camera was just a part of the actor but didn't move at all.

Now movement is based on the pawn finding the nearest object type and making a few checks to see if it fits some criteria. It then outputs the object and I'm telling the pawn to move to the root of that object. I've done this because I intend to have some of the poles seen in the video move during run time and this was the best solution I could come up with.

I've seen other's describe the solution to this but I don't understand how to execute. "After reading around some I found a solution

"Give each pawn its own AI Controller (PlayerController should work fine too I think) and have a master PlayerController act like the "brain" which routes the commands to them. As long as each pawn has its own controller you can move them at the same time on controller index 0 Solved - and thanks!"

avatar image ThompsonN13 May 09 '18 at 03:43 PM

ok this makes a bit more sense now so theres two characters and you want to be able to move both. and your going to be using tow separate sets of input im guessing such as wasd for one character and the arrow keys for the other. in that case you will just need a custom ai controller that an accept the players input. ill try to make an example when i get back from work.

avatar image Alunnite May 09 '18 at 03:54 PM

Yes that sound's exactly like what I need. I'll see if I can figure out how to set up a custom ai controller that accepts inputs right now and let you know if I get it working, so you don't have to waste any time. Also thanks in advanced for taking a look at it. I also thought of another solution where the pawn possession changes depending on which input it being used. Not sure if that would be a valid alternative approach though.

dsc-0133.jpg (5.1 MB)
avatar image ThompsonN13 May 09 '18 at 10:29 PM

i came up with another solution that is easy to implement and seems to work. instead of messing around with all the ai controllers and things why not just reference the characters and set their movement from the one player controller. what this means is that all the code will be centralized and be easier to write and debug. the one problem with this method is that you need to know how many characters you need to control beforehand, but in your case it seems like you want to only have two the entire game right so no problem there.

the way i implemented this for testing was to spawn in two character at the beginning of the game (you could easily get references by another method) then i set a variable of type actor to the characters i just spawned, this gives me a reference to the actors i will be controlling. from there i just wrote a script for the movement inputs that correspond to each character (w for character 1, up for character 2). im sure this could be streamlined a bit but it works and shouldnt be hard to implement.

alt text

capture.png (209.9 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
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