Unity and Network Part 2: Problem with car movement.

So, basicly I managed to setup a server as I wished to, but now I met another problem, when I try to move a car it, umh, “bugs itself”

the video will explain just better the issue:

and here’s the car script:

var LeftWheel : WheelCollider;
var RightWheel : WheelCollider;
var speed : int;
var CarIsActive = false;

function Start () {
	// I usually alter the center of mass to make the car more stable. I'ts less likely to flip this way.
	rigidbody.centerOfMass.y = -1.5;
}

@RPC
function Update(){
if(CarIsActive){
RightWheel.motorTorque = 1000 * Input.GetAxis ("Vertical") * Time.deltaTime;
LeftWheel.motorTorque = 1000 * Input.GetAxis ("Vertical") * Time.deltaTime;
LeftWheel.steerAngle = 10 * -Input.GetAxis("Horizontal");
RightWheel.steerAngle = 10 * -Input.GetAxis("Horizontal");
LeftWheel.brakeTorque = 00;
RightWheel.brakeTorque = 00;

if(Input.GetAxis ("Jump")){
LeftWheel.brakeTorque = 50;
RightWheel.brakeTorque = 50;
		}
	}
}

function MoveCar(){
}

And I will not toleratre these questions:

  1. Have you added the Network View? (YES, And I made it unreliable because the server can manage it)

Did you observe the correct script with your NetworkView?

I kind of observed every object of the whole map!

here’s a screen:

You error is simple: You need to instantiate the object from the client.

You Sure? I’ll try it right now.

fholm is right, but that’s not the whole story. There’s a few things you’re doing wrong.

I don’t think you want the RPC attribute on your Update, as that will send the Update every frame to the server, but the server will also execute Update(). You probably want something like if (networkView.isMine) MoveCar() and throw all that code into MoveCar, which would have the RPC tag.

Then you want to ensure you have a network view that is observing the rigidbody, not the transform. The rigidbody will replicate the physics over properly, not just the position. I believe you can look that up in the docs, I’m not entirely sure you can get away with just replicating the rigidbody without replicating the wheels as I haven’t done a racing game before.

But that will at least make it look correct on the LAN/localhost.

Yeah, don’t care about the @RPC part, I tried that because I had (and still don’t have no clue).

I don’t have any clue about how to instantiate the car in the world AND make it connect to the camera at the same time.

Well, the problem is officially solved, thanks for the help you gave me.