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 Howie · May 16, 2013 at 06:35 AM · cameramultiplayerthird-person

How do I get camera and movement controls for third person multiplayer to work correctly?

Hi everyone,

I'm pretty new to coding and using unity so hopefully there is an obvious solution to my problem. I'm trying to combine a few different tutorials and its not working out so hot. The problem I'm running into is when I add a second player to my server. I can control the camera with one instance but not the movement and with the other instance I can control the movement but not the camera.

Thank you very much for any help in advance!

These are the main blocks of code that I think are relevant, please let me know if you need to see something else.

TPCamera:

 void Start()
     {
         
         //if(networkView.isMine)
         //{
             //make sure min < distance < max
             Distance = Mathf.Clamp (Distance,DistanceMin,DistanceMax);
                 
             //set start distance
             startDistance = Distance;
                 
             //set initial values for camera (position/distance)
             Reset();
         //}
         //else
         //{
             //enabled = false;
         //}
         
     }
     
     void LateUpdate()
     {
         //if(networkView.isMine)
         //{
             //check for targetlookat, if it doesn't exist don't update
             if (TargetLookAt == null)
                 return;
                 
             HandlePlayerInput();
                     
             var count = 0;
             do
             {
                 CalculateDesiredPosition();
                 count++;
             } while (CheckIfOccluded(count));
                     
             UpdatePosition();
         //}
         //else
         //{
             //enabled = false;
         //}
     
     }

If I uncomment the if statments for networkView.isMine the camera doesn't respond at all, even with just one player, and I'm very confused as to why. I also made sure that on my main camera I have a Network View Component added, which to my understanding lets the object be seen by other instances over the network, i could be wrong about that though ... This is all brand new to me.

One major difference I noticed with the networking tutorial I was following was that he has his camera attached to his player game object while my camera and player are separate game objects, could that be an issue?

Here is my TPController class:

 void Awake() 
     {
         
         if(networkView.isMine)
         {
             //allows us to reference this class in other classes?
             CharacterController = GetComponent("CharacterController") as CharacterController;
             Instance = this;
             TPCamera.UseExistingOrCreateNewMainCamera();
         }
         else
         {
             enabled = false;
         }
     }
 
     void Update() 
     {
         if(networkView.isMine)
         {
             //if camera doesn't exist stop everything
             if (Camera.mainCamera == null)
                 return;
             
             GetLocomotionInput();
             HandleActionInput();
             
             TPMotor.Instance.UpdateMotor();
         }
         else
         {
             enabled = false;
         }
     }

I also have a MovementUpdate method which I put on my camera and player character:

 public class MovementUpdate : MonoBehaviour {
     
     private Vector3 lastPosition;
     
     private Quaternion lastRotation;
     
     private Transform myTransform;
 
     void Start() 
     {
         if(networkView.isMine)
         {
             myTransform = transform;
             
             //ensure everyone sees player at correct location
             
             networkView.RPC ("updateMovement",RPCMode.OthersBuffered,myTransform.position,myTransform.rotation);
         }
         else
         {
             enabled = false;
         }
     }
 
     void Update() 
     {
         //if player has moved then fire off RPC to update player's position and rotation
         
         if(Vector3.Distance(myTransform.position, lastPosition) >= 0.1)
         {
             //capture player's position before RPC is fired and use this to determine in player has moved in if statement above
             
             lastPosition = myTransform.position;
             
             networkView.RPC ("updateMovement",RPCMode.OthersBuffered,myTransform.position,myTransform.rotation);
         }
         
         if(Quaternion.Angle(myTransform.rotation, lastRotation) >= 1)
         {
             //capture player's rotation before RPC is fired and use this to determine in player has turned in if statement above
             lastRotation = myTransform.rotation;
             
             networkView.RPC ("updateMovement",RPCMode.OthersBuffered,myTransform.position,myTransform.rotation);
         }
     }
     
     [RPC]
     void updateMovement (Vector3 newPosition, Quaternion newRotation)
     {
         transform.position = newPosition;
         transform.rotation = newRotation;
     }
 }



These are the tutorials I've been working off of:

http://www.3dbuzz.com/training/view/3rd-person-character-system

http://www.youtube.com/watch?v=J4j4vlso4yc&list=PLC90282759FD90F77

Comment
Add comment · Show 1
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 Fattie · May 16, 2013 at 06:37 AM 0
Share

@Howie, most moderators would just reject this question since, very long questions are never answered or even read. This forum is for really specific questions like "what is 82 degrees of dot product" or whatever.

Also,

the usual stock rejection response to "help with XYZ tutorial" is "question rejected, please ask the people at XYZ tutorial"

Finally you seem to be doing $$anonymous$$P networking here which is pretty advanced and it's difficult to answer "basic program$$anonymous$$g help" questions when one is dabbling in the most advanced fields.

So hopefully someone will magic a suggestion for you but really it is likely some other moderator will just close this

0 Replies

· Add your reply
  • Sort: 

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

14 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

Related Questions

Have Camera Render First Person Arms But Not Body. 2 Answers

3rd person camera that avoids objects 0 Answers

2 players 1 game field in shooter/card game 0 Answers

Multiplayer click and spawn 1 Answer

Need help for player rotation and camera rotation 0 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