Attaching driver to a vehicle in multiplayer

I am trying to attach my first person pawn to a vehicle in multiplayer, on the listen server it works perfectly, but if a client gets on a car I can control the car perfectly but it kind of jumps around and seems jittery… I’ve been suspecting maybe its something with the fact there’s a pawn with a CharacterMovement component attached to a vehicle with a VehicleMovement component, or maybe something with the Vehicle’s movement being replicated and it going crazy jumping around…

I’ve disabled the movement on the CharacterMovement of the pawn by calling DisableMovement and I also disabled the collision of the CapsuleComponent before attaching the pawn to the vehicle mesh.

Any idea?
Thank you.

Sounds like something’s wrong with the replication structure. Can you double-check it?

I’m not sure what you mean by that. Both the car and the pawn replicate and both replicate their movement, I tried disabling replication of the movement of the pawn but it doesn’t help. Could it be related to the fact that when the pawn gets on a vehicle it keeps a pointer to it and calls its set throttle and set steering functions from there? (I had to set the controller value on the vehicle to the player’s controller in order for it to work).

I’m not sure. Can you send some screenshots?

To attach the character to the car I use the following code. This runs on all the clients via a RepNotify.

CurrentVehicle = NewCar;
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
GetCharacterMovement()->DisableMovement();
GetCharacterMovement()->bEnablePhysicsInteraction = false;
this->AttachRootComponentTo(NewCar->GetMesh(), FName(TEXT("CharacterSocket")), EAttachLocation::SnapToTarget, true);
//problem is not weld simulated targets... tried without it
NewCar->Controller = this->GetController();
NewCar->SetOwner(this);

And the car is controlled like this from the character pawn:

if (CurrentVehicle)
{
	CurrentVehicle->GetVehicleMovement()->SetThrottleInput(Value);
}

Here’s the replication tab for both the car and the pawn:


Here’s a video of the problem:
[LINK][2]

(remember that on host it works perfectly so I guess its probably something with prediction or some physics screwup…)

Does jittering stop when the vehicle’s stationary? If so, my guess would be that it’s happening because of latency. They solve this problem in GTA V by replicating the client version of the car and host character based on the client character location. It’s not a perfect solution but stops jittering.

Jittering does stop when the vehicle is stationary. When I actually possess the vehicle it works perfectly so it must be something with the character being parented to the vehicle. A workaround to all this jittering is setting the characters location every tick to the car’s socket location, but that solution seems kinda dirty and I want to know the real cause of the problem.

Sometimes delays/jittering occur with attached components and actors even in single player games. This might be an issue independent from the network actually. I would go with the dirty solution if it works.

Hmm, makes sense. Its weird that it works perfectly on the host machine though. But thank you very much :slight_smile:

I had this exact problem. Disable the charactermovementcomponent, it applies smoothing which messes things up.

Although I still get some issues placing the character, but it no longer jitters.

2 Likes

That did it, thank you :slight_smile:
I disabled the CharacterMovement component via

GetCharacterMovement()->SetComponentTickEnabled(false);

(and re enabled it doing the same with a true bool)

Is that the right way to disable a component?

DisableComponent