Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Fr0sT3iTT3N · Sep 29, 2015 at 05:04 PM · c#collisionrigidbodynetworkingphoton

Network Rigidbodies act weird?

Hello, so I have some players in my game (player controller script using rigidbodies) I'm using Photon Networking and everything is working but, when the two players collide in the game, the collision is very weird, it like moves... but not how it should. Think of a ball going North at 30 mph (ball a). Now think of another ball coming from the West at 60 mph(ball b). ball b hits ball a but all ball a does is goes Northnortheast... at 15mph... Sometimes ball a doesn't even seem like it got hit. Also, I tried throwing in a sphere, with a rigidbody and no network stuff, and the collisions were perrfffffect. If anyone could help me with this problem it would be great. Thanks. Here is my Character Controller:

 using UnityEngine;
 using System.Collections;
 
 public class BallMoverP2 : Photon.MonoBehaviour {
     
     
     public bool IsGrounded;
     
     
     public Camera firstPerson;
     public Camera thirdPerson;
     public float moveSpeed;
     public float jumpSpeed;
     public bool CamToggler;
 
 
     
     void Start ()
     {
         //if (Camera == null)
         //Camera = Camera.FindGameObjectsWithTag ("Camera");
         CamToggler = true;
     }
 
 
     void FixedUpdate(){
 
             if (Input.GetButtonDown ("ToggleCamera")) {
                 //CamToggler = ! CamToggler;
             }
         
             if (Input.GetButton ("Left") && CamToggler == true) {
             GetComponent<Rigidbody> ().AddForce (-firstPerson.transform.right * moveSpeed * Time.deltaTime, ForceMode.Impulse);
                 //GetComponent<Rigidbody> ().AddTorque (-firstPerson.transform.right * moveSpeed * Time.deltaTime);
             }
             if (Input.GetButton ("Left") && CamToggler == false) {
             GetComponent<Rigidbody> ().AddForce (-thirdPerson.transform.right * moveSpeed * Time.deltaTime, ForceMode.Impulse);
                 //GetComponent<Rigidbody>().AddTorque( -thirdPerson.transform.right * moveSpeed * Time.deltaTime);
             }
 
         
             if (Input.GetButton ("Right") && CamToggler == true) {
             GetComponent<Rigidbody> ().AddForce (firstPerson.transform.right * moveSpeed * Time.deltaTime, ForceMode.Impulse);
                 //GetComponent<Rigidbody> ().AddTorque (firstPerson.transform.right * moveSpeed * Time.deltaTime);
             }
             if (Input.GetButton ("Right") && CamToggler == false) {
             GetComponent<Rigidbody> ().AddForce (thirdPerson.transform.right * moveSpeed * Time.deltaTime, ForceMode.Impulse);
                 //GetComponent<Rigidbody>().AddTorque( thirdPerson.transform.right * moveSpeed * Time.deltaTime);
             }
         
             if (Input.GetButton ("Forward") && CamToggler == true) {
             GetComponent<Rigidbody> ().AddForce (firstPerson.transform.forward * moveSpeed * Time.deltaTime, ForceMode.Impulse);
                 //GetComponent<Rigidbody> ().AddTorque (firstPerson.transform.forward * moveSpeed * Time.deltaTime);
             }
             if (Input.GetButton ("Forward") && CamToggler == false) { 
             GetComponent<Rigidbody> ().AddForce (thirdPerson.transform.forward * moveSpeed * Time.deltaTime, ForceMode.Impulse);
                 //GetComponent<Rigidbody>().AddTorque( thirdPerson.transform.forward * moveSpeed * Time.deltaTime);
             }
         
             if (Input.GetButton ("Backward") && CamToggler == true) {
             GetComponent<Rigidbody> ().AddForce (-firstPerson.transform.forward * moveSpeed * Time.deltaTime, ForceMode.Impulse);
                 //GetComponent<Rigidbody> ().AddTorque (-firstPerson.transform.forward * moveSpeed * Time.deltaTime);
             }
             if (Input.GetButton ("Backward") && CamToggler == false) {
             GetComponent<Rigidbody> ().AddForce (-thirdPerson.transform.forward * moveSpeed * Time.deltaTime, ForceMode.Impulse);
                 //GetComponent<Rigidbody>().AddTorque( -thirdPerson.transform.forward * moveSpeed * Time.deltaTime);
             }
             if (IsGrounded == true && Input.GetButtonDown ("Jump")) {
                 IsGrounded = false;
                 GetComponent<Rigidbody> ().AddForce (Vector3.up * jumpSpeed, ForceMode.Impulse);
                 //GetComponent<Rigidbody> ().AddTorque (Vector3.up * jumpSpeed, ForceMode.VelocityChange);
             }
             if (Input.GetButton ("Run")) {
                 moveSpeed = 200.0f;
             } else {
                 moveSpeed = 100.0f;
             }
 
         
         
     }
 
     
 
     void OnCollisionEnter(Collision collisionInfo)
     {
         IsGrounded = true;
     }
     
     //void OnCollisionExit (Collision collisionInfo)
     //{
     //    IsGrounded = false;
     //}
 }

And my NetworkCharacterRead/writer:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkCharacter : Photon.MonoBehaviour {
     Vector3 realPosition = Vector3.zero;
     Quaternion realRotation = Quaternion.identity;
     Vector3 realVelocity = Vector3.zero;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void FixedUpdate () {
     if (photonView.isMine) {
             //do nothing
         } else {
             GetComponent<Rigidbody>().position = Vector3.Lerp(GetComponent<Rigidbody>().position, realPosition, 0.1f);
             GetComponent<Rigidbody>().rotation = Quaternion.Lerp(GetComponent<Rigidbody>().rotation, realRotation, 0.1f);
             GetComponent<Rigidbody>().velocity = Vector3.Lerp(GetComponent<Rigidbody>().velocity, realVelocity, 0.1f);
         }
 
     }
     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
 
         if (stream.isWriting){
         stream.SendNext (GetComponent<Rigidbody>().position);
         stream.SendNext (GetComponent<Rigidbody>().rotation);
         stream.SendNext (GetComponent<Rigidbody>().velocity);
     }else{
             realPosition = (Vector3)stream.ReceiveNext();
             realRotation = (Quaternion)stream.ReceiveNext();
             realVelocity = (Vector3)stream.ReceiveNext();
 
 
         }
     }
 }

And my Network Manager:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : Photon.MonoBehaviour {
 
     public GameObject StandbyCamera;
     SpawnSpot[] spawnSpots;
     public bool CamToggler;
 
     // Use this for initialization
     void Start () {
         spawnSpots = GameObject.FindObjectsOfType<SpawnSpot> ();
         Connect ();
 
     }
 
     
     void Connect()
     {
         PhotonNetwork.ConnectUsingSettings("v1.0");
         Debug.Log ("Connecting...Baby");
     }
     void OnGUI() 
     {
         GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
     }
 
     void OnJoinedLobby()
     {
         Debug.Log ("JoinedLobbyBaby");
         PhotonNetwork.JoinRandomRoom ();
     }
     void OnPhotonRandomJoinFailed()
     {
         Debug.Log("CRAP!JoinRandomLobbyFailed");
         PhotonNetwork.CreateRoom (null);
     }
     void OnJoinedRoom()
     {
         Debug.Log ("JoinedRoomBaby");
 
         SpawnMyPlayer ();
     }
     void SpawnMyPlayer ()
     {
         if (spawnSpots == null) {
             Debug.LogError ("CRAP! There is no freaking spawn spots!?");
             return;
         }
         SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)];
         Debug.Log ("LET THERE BE A PERSON");
         GameObject myPlayerGo = (GameObject)PhotonNetwork.Instantiate ("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
             
         StandbyCamera.SetActive (false);
         myPlayerGo.GetComponent <BallMoverP2> ().enabled = true;
         //myPlayerGo.GetComponent <MouseLook> ().enabled = true;
         GameObject myCamGo = myPlayerGo.transform.Find ("AXLEP1").gameObject;
         GameObject CamGo1st = myCamGo.transform.Find ("Cam1st").gameObject;
         GameObject CamGo3rd = myCamGo.transform.Find ("Cam3rd").gameObject;
         CamGo3rd.SetActive (false);
         CamGo1st.SetActive (true);
 
     }
 

Thanks for taking the time to read this far :)

Comment
Add comment
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

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

34 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 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

C# Photon Networking - Preventing duplicate GameObjects from spawning on Join. 1 Answer

Check what group id you have after being instantiated. (PUN) 1 Answer

hi guys am having a problem with my player 0 Answers

Unity Annoyance with Physics Help C# Scripting Problem Momentum Issue Please Help 0 Answers

Unity Photon Handle Match Data 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