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 joshcollins5 · Nov 30, 2014 at 10:43 PM · thirdpersoncontrollersplitscreen

Splitscreen issue, second camera inverts controls.

Hi, I am currently working on a game of which contains splitscreen levels, using two Xbox 360 Controllers.

I have all input working, as well as a working splitscreen layout, however, I am stuck with an issue of which one out of the two cameras set up doesn't update the direction of the player properly, making it so that when focusing on the character on the screen with the issue, if you turned and moved, it would be inverted, but will uninvert in certain locations of the map and then back again.

I have looked into the code as I am using the default ThirdPersonController for both characters and I am currently using the SpringFollowCamera script too.

One thing I should point out is that if I change one of the two cameras's tag from MainCamera to something else, the one of which is still the MainCamera works with no issue. This happens the other way around with the other character and camera.

Something that I thought was worth noticing is that in the script for the ThirdPersonController, there is a section about updating the character's facing direction with the camera, and I have tried tweaking it with no luck, so I reverted it back to the way it was. Here it is:

 function UpdateSmoothedMovementDirection ()
 {
     var cameraTransform = Camera.main.transform;
     var grounded = IsGrounded();
     
     // Forward vector relative to the camera along the x-z plane    
     var forward = cameraTransform.TransformDirection(Vector3.forward);
     forward.y = 0;
     forward = forward.normalized;
 
     // Right vector relative to the camera
     // Always orthogonal to the forward vector
     var right = Vector3(forward.z, 0, -forward.x);
 
     var v = Input.GetAxisRaw("updn");
     var h = Input.GetAxisRaw("leftnr");
 
     // Are we moving backwards or looking backwards
     if (v < -0.2)
         movingBack = false;
     else
         movingBack = true;
     
     var wasMoving = isMoving;
     isMoving = Mathf.Abs (h) > 0.1 || Mathf.Abs (v) > 0.1;
         
     // Target direction relative to the camera
     var targetDirection = h * right + v * forward;
     
     // Grounded controls
     if (grounded)
     {


I am looking for somebody to help optimize this code so the one camera that is faulty is fixed, then I can finally move on and finish this feature.

Thank You very much for reading and I hope to get a reply as soon as possible, thanks.

Comment
Add comment · Show 2
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 HarshadK · Dec 01, 2014 at 01:42 PM 0
Share

Can you share what errors you get? Sometimes it might be these errors and not the actual logic that is preventing you from reaching the required output.

avatar image joshcollins5 · Dec 01, 2014 at 04:03 PM 0
Share

There are no errors in the compiler, just a faulty camera. I really need to know how to make a public camera field as thelacky3326 mentioned, then this problem is resolved :)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by thelackey3326 · Dec 01, 2014 at 04:58 AM

Camera.main will only return the first camera found called "MainCamera". If you have two Third Person Control scripts running, and two GameObjects tagged as MainCamera, then one of the scripts will find the other object and not the camera it's attached to. You should probably augment the script so that you can assign the camera that you want it to control, i.e. make a public Camera field and drag the Camera to it in the inspector.

Comment
Add comment · Show 2 · 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
avatar image joshcollins5 · Dec 01, 2014 at 01:40 PM 0
Share

Thanks for the reply, I am relatively new to coding and I am unsure how to go about this exactly. I have tried to edit the above code in order to suit this but I keep getting errors, is there anything specific I can put into this code that you have in $$anonymous$$d? Thanks.

avatar image joshcollins5 · Dec 02, 2014 at 06:06 PM 0
Share

After reading this again I have thought it would be important to note that both characters are using two seperate identical scripts each in order to work, just renamed and reassigned, like I say all input works perfectly.

I have tried editing the .mainCamera code into something else but I cannot seem to find something that would work, what I meant by error is that nothing seems to happen, I should have been more specific. If there is anything anyone wants to suggest, please let me know, I need this finishing before Christmas.

Thanks.

avatar image
0

Answer by joshcollins5 · Dec 02, 2014 at 07:23 PM

Problem solved, thanks for your answers. I managed to make a new public variable in the top of the controller script and put assign next to it.

I then put that variable.transform where the main.camera was and now it is fixed :D

Comment
Add comment · Show 1 · 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
avatar image thelackey3326 · Dec 03, 2014 at 02:27 AM 0
Share

Sorry I couldn't get back to you sooner! Looks like you have a solution, though. Good luck!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Have I to disable the gravity to drag an object? 1 Answer

Third Person Controller Custom Characterstates 0 Answers

Negitive Input Problem 0 Answers

Splitscreen, players in differnt scenes 0 Answers

Third person controller not being destroyed although script works 1 Answer


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