# In multiplayer Physics and Scripting Problem

Discussion in 'Physics' started by aaronrotc2014, Feb 17, 2015.

1. ### aaronrotc2014

Joined:
Apr 17, 2014
Posts:
7
So here is my question. how do i get this to work for pushing another Character Controller for multiplayer?

Code (JavaScript):
1.
2.     var pushPower = 2.0;
3.     var overallSpeed = 0;
4.     var relativeSpeed = 0;
5.
6. function Update() {
7.
8. }
9.
10. function OnControllerColliderHit (hit : ControllerColliderHit) {
11.         var body : Rigidbody = hit.collider.attachedRigidbody;
12.         // no rigidbody
13.         if (body == null || body.isKinematic)
14.             return;
15.
16.         // We dont want to push objects below us
17.         if (hit.moveDirection.y < -0.3) return;
18.
19.         // Calculate push direction from move direction,
20.         // we only push objects to the sides never up and down
21.         var pushDir : Vector3 = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
22.         // If you know how fast your character is trying to move,
23.         // then you can also multiply the push velocity by that.
24.
25.         // Apply the push
26.         body.velocity = pushDir * pushPower;
27.
28.         // On collision, get speed of controller
29.         var controller : CharacterController = GetComponent(CharacterController);
30.         var overallSpeed = controller.velocity.magnitude;
31.
32.         // Get the Ratio for the Push Power. > overallSpeed = > Knock Back on Object
33.         var pushPowerRatio = overallSpeed * 0.3;
34.
35.         // Apply the push, multiplied by pushPowerRatio
36.         body.velocity = pushDir * pushPower * pushPowerRatio;
37.
38. }

2. ### aaronrotc2014

Joined:
Apr 17, 2014
Posts:
7
or to push a rigidbody

Joined:
Feb 17, 2015
Posts:
4
Not sure if I understand your question.
Normally the physics happen on one client and the results are then in some form carried over to the others. You would not communicate the whole physical process via network. that would be unnessecary information.

Hope that helps somehow, although I am a beginner as well.

Also watch out if you make calculations on both ends. Something like this could happen (at 1:00:30)
http://unity3d.com/learn/tutorials/...ining-archive/merry-fragmas-multiplayer-fps-2