Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jacobhanshaw · Dec 05, 2013 at 09:44 PM · multiplayersorting layerslevel-designsplit-screen

Split-Screen without Showing Other Player

So I'm working on a game and I'd like to make it competitive by having players race along the same level/scene in a split-screen format. However, ideally I would like the players to not be able to interact or even show up in each other's screens.

What would be the best way to do this?

My naive initial approach would be to load 2 scenes, but I don't know if you can load the same scene twice. I looked around and layers might work, but my wishes are that:

Interactions with the level be limited to each screen. I.E. if one players uses an elevator, the elevator only moves in that player's scene.

There is a potential for a cooperative 2 v 2 element, so some players need to be able to interact, but not others. This seems to point to the fact that using layers wouldn't work without an obtrusive layer naming scheme.

Edit: The players that would interact with each other would be in the same screen. That line was meant to say that I don't think simply masking that Players can't interact with other Players would work as I want two people working together in one screen and two people working together on the other.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Commander Quackers · Dec 05, 2013 at 10:02 PM 0
Share

Use culling masks on the cameras.

avatar image tanoshimi · Dec 05, 2013 at 10:10 PM 0
Share

"if one players uses an elevator, the elevator only moves in that player's scene." - that requirement is a bit of a killer: no amount of layers/camera culling is going to handle a gameobject that has both moved and not moved.... you're basically describing two independent instances of the scene. But then that gets kicked in the teeth by "some players need to be able to interact, but not others".

I think you're going to need a much clearer and more detailed design to think through the options - it sounds like it will complex and bespoke.

avatar image jacobhanshaw · Dec 05, 2013 at 10:24 PM 0
Share

tanoshimi-

You're right. I apologize for my ambiguity. I thought that two independent scenes might be my only answer, but I'm not sure about how to go about that.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 05, 2013 at 10:50 PM

You can't really load two scenes at the same time, however you could load the same scene additivly into the current scene so all objects are actually duplicated. While this does work i don't think that's a good approach in the end. You still have to move the two "content packages" so they don't overlap. It's probably easier, if there are only a few of those cooperative elements, to use one scene with layers.

All geometry that doesn't change individually is on a layer that both players can interact with. Each player has it's own extra layer where it is actually placed in. Both player layers can collide with the common layer (you can use the default layer as common layer). You would simply disable collisions between the two player layers and remove the opposite player layer from your cameras culling mask.

So far for the general approach. Now the "splitted objects" where each player needs it's own version. Initially you have the object only once. That simplyfies the level design. Now you just attach a script to those object which will duplicate the object itself, assign the duplicated object to player 1 and the original to player two.

Important: This duplicating should be done in Start and at the end of Start you have to prevent that the script on the cloned object does the same or you end up with getting a new clone each frame.

This can be done by adding a bool which is initially false and get set to true by the original object.

Example:

 //C#
 public class SplitObject : MonoBehaviour
 {
     public bool isClone = false;
     public SplitObject other = null;
     void Start()
     {
         if(!isClone)
         {
             SplitObject clone = (SplitObject)Instantiate(this);
             clone.isClone = true;
             gameObject.layer = LAYER_PLAYER1;
             clone.gameObject.layer = LAYER_PLAYER2;
             other = clone;
             clone.other = this;
         }
     }
 }

This script will duplicate the object it's attached to and assigns itself to player1 and the clone to player2. I've added a cross link reference to the other object in each instance. That way it's easier to link up signals from triggers ect...

Everytime one of those splitted objects want to communicate with a linked object it has to check if itself is a clone (isclone) and then use the "other" reference to "fix" the link.

Example:

A trigger which sends a message to a door might look like this:

 // C#
 public class SplittedDoorTrigger : MonoBehaviour
 {
     public GameObject target;
     void Start()
     {
         var SO = GetComponent<SplitObject>(); // get own instance of SplitObject.
         if (SO.isClone) // check if we are the cloned object
         {
             var splittedTarget = target.GetComponent<SplitObject>().other.gameObject;
             target = splittedTarget;
         }
     }
     void OnTriggerEnter(Collider aOther)
     {
         target.SendMessage("Open");
     }
 }

In this example both the door and the door-trigger have a SplitObject component which will duplicate the trigger and the door and assign it to the corresponding player. The target reference however will still point to the original target. That's why this code will check if it is a clone and if so it grabs the original target, get the SplitObject instance of the target, use the "other" reference to get the cloned object and use this as target.

A bit complicated but should work ;)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Split-Screen 2 players in different scenes but same game (offline),Split-screen two players in separate scenes (offline) but same game? 1 Answer

Split screen without two cameras in 2D versus game? 1 Answer

Restricting Canvas navigation for each player 0 Answers

Any clues on how to create a split-screen effect like the lego harry potter game? 3 Answers

How to do a multiplayer split-screen game on one computer? 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges