Announcement

Collapse
No announcement yet.

Switch between Player Controlled Pawns and AI Controlled Pawns.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Switch between Player Controlled Pawns and AI Controlled Pawns.

    Hi,

    I need to be able to switch between multiple characters and have AI take control of any characters not currently being controlled by the player.
    Currently I have multiple "Player Characters" placed in the level and use the number keys to switch between character possesion using the number keys, as explained here:

    https://docs.unrealengine.com/latest...nts/index.html

    I am using Character Blueprints, though i'm a little confused with the difference between each tbh...

    EDIT: From what I can tell I think i'm using the wrong type of Blueprint for characters and should just be using Pawns... The game I am looking to make is an UE4 version of the PS1 game "Team Buddies". You pretty much use crates to "craft" characters, then fight other teams using those characters.

    If anybody could thrown me into the right direction that'd be great. I've currently watched the "Introduction to Blueprints" and " Third Person Character Blueprints"
    Thanks for your help
    Last edited by funkbro; 02-23-2015, 09:33 AM.

    #2
    AI can absolutely drive Character BPs. Source: it's how I do enemies in my game.

    What drives the Character is the CONTROLLER; by default your character is driven by a Player Controller, but it doesn't have to be.

    You can "Unposess" and "Posess" a Character at any time, the same way you would a Pawn; to have the AI take over a character you would just Unpossess your character, then Possess him with an AI Controller as the Target instead... Then you would Unpossess some AI-controlled actor, then Possess him with the Player Controller as the target.

    Depending on the game, what I would do is, upon Spawning the "default" character (so, on the default character's Event Begin Play), also spawn whatever secondary characters you need, by default using AI controllers. That way you can store all of the alternate characters as variables on your main character and easily access them when you want to Possess them.
    Last edited by RhythmScript; 02-23-2015, 02:15 PM.

    Comment


      #3
      Thanks for the awesome response, RhythmScript. I understand everything you've said, which is a good start , now it's time to actually get something working!

      Comment


        #4
        Ok, so i'm a little confused with this...

        I currenly have this blueprint:

        http://gyazo.com/7f6bfc48087aa4861147104b942f50ef

        When I possess either of the 2 placed characters in my level, it no longer lets me press 1 to return control to the default character...
        Also could somebody tell me or give me some hints to possessing the uncontrolled characters with AI.

        I have a Basic AI controller made with the Behaivour Tree and Blackboard quickstart tutorial. I just can't figure out how to have the AI Controller Posses the uncontrolled character

        http://gyazo.com/0de266f403df8441fc329faf8c70eedc

        Cheers
        Last edited by funkbro; 02-26-2015, 10:42 AM.

        Comment


          #5
          First: remember that Input events are only handled by the actor which has a player controller. You'll need to make sure you duplicate that switching logic on all controllable characters, otherwise switching off player 1 will leave you attached to a character that doesn't do anything when you hit 2.

          Second, do you see the "Target" pins that you have connected to the playercontroller? Just connect them to an AIcontroller reference instead.

          Comment


            #6
            Thanks again RhythmScript!

            I've got the Ai possession working but pressing 1 still doesn't return control to the default character...

            http://gyazo.com/4af4186ba10fbd830fabf8f4af6f291b

            1. I press play and begin moving as my Default Character.
            2. After I press 2 or 3 my controller possesses either "MyCharacter2" or "MyCharacter", pressing either 2 or 3 moves back and forth to the corresponding character fine.
            3. When I press 1 to return control to the original default character, nothing happens...

            Is something stopping the Level Blueprint from referencing the "DefaultCharacter" variable as the initial player character at index 0?
            Once again thanks for your help, it means a lot .

            Comment


              #7
              I am boggled... I have done numerous AI tutorials but for some reason this just isn't working, I can't get my head around why it's not working...

              I have done the guard Ai tutorial here: https://www.youtube.com/watch?v=A_rnZ_2PgpM

              My AI Controller, BlackBoard/Behavior Trees all work fine, if I set the "Auto Possess AI" on the "Character Blueprint" to "Placed in World", then the character starts moving to the "Target location".
              Here's a GIF showing the third character walking to it's Target, and the character switch working:

              http://gyazo.com/117ceb6e89dd03b7302ddab90b227d76

              I want to be able to Possess the Character with it's AI Controller when I press 3, but it just doesn't work...

              Here's the level blueprint I have which isn't working...

              http://gyazo.com/4bd900c6dc881e89b7f4e071d3a840cc

              Thanks

              Comment


                #8
                Your AI commend block does nothing. The controller which is already in Pawn 3 is possessing it again.

                Comment


                  #9
                  For anyone still trying to switch between player and AI controllers, all you need is the Spawn Default Controller node and as target put the character that you need to be possesed by the AI.Here is my setup and it works like a charm! In the character options set AutoPossessAI to "placed in world" Click image for larger version

Name:	ai Switch.jpg
Views:	1
Size:	201.4 KB
ID:	1103545

                  Comment


                    #10
                    Originally posted by Xander Moss View Post
                    For anyone still trying to switch between player and AI controllers, all you need is the Spawn Default Controller node and as target put the character that you need to be possesed by the AI.Here is my setup and it works like a charm! In the character options set AutoPossessAI to "placed in world" [ATTACH=CONFIG]86209[/ATTACH]
                    Thanks man! It worked for me! (looking for hours)

                    Comment


                      #11
                      It worked, but I think the World Outliner gets cluttered with AI controller after a lot of switches, is there a way to get rid of old AI controllers?

                      Comment

                      Working...
                      X