Car Collision Script with Photon
Goal: Multiplayer collision physics! I have been trying to get this working for hours and I tried everything I could think of. I would like a car to move in the direction that it was struck by another car.
The car is a prefab with a (non-kinematic)rigidbody, so both GameObject's that are colliding have rigidbodies! Everything is being called correctly but the final result of the AddForce is not working the way I had hoped or I'm not using the correct photon target when calling my rpc!
This is what I'm working with right now:
The car is a prefab with a (non-kinematic)rigidbody, so both GameObject's that are colliding have rigidbodies! Everything is being called correctly but the final result of the AddForce is not working the way I had hoped or I'm not using the correct photon target when calling my rpc!
This is what I'm working with right now:
void OnCollisionEnter(Collision collision) { Debug.Log("Collision!"); Velocity = collision.relativeVelocity; Debug.Log(Velocity); NObjectHit = collision.transform.root.gameObject.name; Debug.Log(NObjectHit); photonView.RPC("CreateCollision", PhotonTargets.AllViaServer, Velocity, NObjectHit); } [PunRPC] public void CreateCollision(Vector3 velocity, string nobjecthit) { Debug.Log(nobjecthit + "RPC"); rigid = GameObject.Find(nobjecthit).GetComponent(typeof(Rigidbody)) as Rigidbody; if (rigid != null) { rigid.AddForce(velocity * 1000); Debug.Log("Added Force"); } }
0
Comments
-
Sorry, I think I put this in the wrong category. But I don't know how to change it!0