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"

get two players in a game (single player)

Hello,

I am trying to get two players in a game where the player can control two separate characters on the same keyboard (similar to the game Two Brothers). I am using the basic C++ side scroller project and I am trying to make a copy of the character to make another one spawn. I tried adding another Player start, but I don't know how to link that with a second player. I am not trying to do a multiplayer game so I am unsure how to have another character in the game. Any help would be great! Thanks!

Product Version: Not Selected
Tags:
more ▼

asked Jan 24 '15 at 12:03 PM in C++ Programming

avatar image

omalleym
8 4 7 10

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

1 answer: sort voted first

Search API reference more ;]

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Kismet/UGameplayStatics/CreatePlayer/index.html

UGameplayStatic::CreatePlayer(GetWorld(),-1,true);

The lest bool decides whatever to spawn and automaticlly posses pawn, if you do false you will need to do the setup for yourself. This function also returns APlayerController of new player so imidietly you can do operations on him once you call this function

more ▼

answered Jan 24 '15 at 03:30 PM

avatar image

Shadowriver
37.2k 936 172 1116

avatar image omalleym Jan 24 '15 at 04:37 PM

Hi Shadowriver, I found that API referance, but I wasn't sure how to use it. Would I place it in the initialize of the character class and how can I give the second player different inputs for him? Can I use a tag in the input and then check that tag for each character? Code attachedlink text

avatar image Shadowriver Jan 24 '15 at 04:46 PM

Things like adding player is part of game rules, so you should have it in AGameMode.

Think a little, when you want add player and plcae this function in right moment

avatar image omalleym Jan 24 '15 at 05:15 PM

Hi Shadowriver, thank you, but I am still a little confused. I placed it in the game mode area and removed the other code, but it is still crashing. I am still new to UE4 (came from unity) so I am confused by the C++ and the lack of sleep from doing a game jam is not helping lol. Here is the new code: link text

avatar image Shadowriver Jan 24 '15 at 06:26 PM

World instance dont exist on constractor so GetWorld return null, you should call it on BeginPlay().

Never place game code in constructor, only place default varables sets there, engine calls constructor not only during game to check default varables, so game code there wont work and will crash the game

avatar image omalleym Jan 24 '15 at 07:19 PM

Ah okay thank you! I placed it inside its own begin play function and that makes a lot of sense. Now I notice that this creates a split screen effect. Is there a way to make them both on one screen? And is there a way to change the second players controls?

avatar image Shadowriver Jan 24 '15 at 11:18 PM

You can disable split screen in project settings as remeber, not sure about controls, you can create 2nd set of bindings and make 2nd playercontroller bind things diffrently

avatar image omalleym Jan 25 '15 at 02:32 AM

okay thank you so much! I have fixed the splitscreen and trying to make the key binds which I think I got, now I just need to get them to bind to the second player controller and I will be all set. If you know the specific, let me know but thank you!

(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