Download

[Video] Player-Controlled Replicating Physics Movement, Simulating Physics!

I have some amazing news!


**Massive Update! ~ Feb 21 2016**

Using a new algorithm that is a hybrid of both input replication and interpolation, I've now accomplished my goal of a game based on replicating player-controlled physics-simulating characters that can also platform freely!

**I can now fully support the network coding for a physics-based platformer multiplayer game!**

You won't believe it but in the video below I am testing with **200 millisecond simulated lag**!

The results are that good!

I am using a completely custom pawn for this, with my own skeletal mesh component! I am not using ACharacter replication system at all.


https://www.youtube.com/watch?v=DLF0OlQ-TzM


I invented an algorithm that supports replication of the movement of meshes that are player-controlled and simulating physics!

Replicating the movement of skeletal meshes that are simulating physics is one level of the issue I’ve been solving,

but the other level is when that replicated skeletal mesh movement is being controlled by a human player!

As you might well know from looking in the code base, replicating player-controlled movements over a realistic network situation is quite complicated!

Well in this video I demonstrate replicating player-controlled movements of physics-simulating skeletal meshes!

Enjoy!


**Realistic Network Lag**

I used these network settings forth both server and client for realitistic network testing!

You can stick the below into a .txt in your Engine/Binaries directory and then run it using exec filename.txt from the console of both clients and server.

Net PktLoss=1
Net PktOrder=0
Net PktDup=0
Net PktLag=75
Net PktLagVariance=0

Video

In the video it looks like I am just rolling around, the reason it is significant is because the movements are replicating properly!

The right window is the client, who is watching the server move around accurately despite having to watch what the listen server is doing across a network!


**Secret Core of Algorithm**

I dont ever do hard "sets" of the Mesh's physics location, I only apply additional forces on the non-player simulated proxies to keep them up to date with what actual player's mesh is doing!

So each client and the server are being told what the correct physics mesh location is, but are then just applying additional forces to the replicated linear and angular velocity to get their proxies to the right position.

The actual player-controlled mesh does not receive any updates so that the player's experience is always smooth, instead the player-controlled mesh is updating all of its proxies over the network. :)

What This Means

This means multiplayer game where all the players are controlling physics simulating skeletal meshes!

Physics-based multiplayer game!

Rama

PS: Epic if you want this tech for ACharacter class, to check when a Character’s mesh is ragdolled and then run my code to keep the simulated ragdoll meshes in sync, let me know!

This looks great, and very relevant to probably most of my work so far in UE4. (Replicated physics-based movement)
I’m curious about your “Secret Core of Algorithm”… Does the player have full authority of their own position?
My implementation has been the client moving their own mesh, but also sending the input so that the server moves it too. Then the client has to trust the server and fix their position every now and then, which is the hard part, as you have to have a good way of fixing their position without rubberbanding.
I’m not sure how similar it is to yours but I’m interested to hear more :slight_smile:

Also, is that a skeletal mesh? It looks like a static mesh :stuck_out_tongue:

Yup! the local player is in control!

:slight_smile:

Yes its a skeletal mesh, it has a lot of morph targeting I did not demo in the video :slight_smile:

Rama

Ah. Wouldn’t this allow a player to potentially hack and just move however they want? (Disable physics or set their location)
Or do you have a way to prevent this?

Nice :slight_smile:
I’ve also toyed with the idea of replicated ragdolls, though I didn’t need mine to be player controlled!
I haven’t got around to trying it in UE4 yet, but I would very much like to get it working eventually.

Not sure what you mean by hacking in this context, the player use WASD to move their physics simulating mesh around the level,

other players have their proxy updated to what the local player is doing with their mesh :slight_smile:

Rama

Ohh great work!

I’d love to see this integrated in the engine itself! My game too would benefit from replicated ragdolls position (for gameplay reasons too, not only cosmetic).

Thanks Ixiguis!

Oh yea, for your gun that pins people to the wall! Good point :slight_smile:

Rama

Is this, in effect, a dynamic character controller?

Because that’s rad. I love dynamic character controllers.

Syncing physics objects is a huge paint - this is awesome.

What exactly do you mean by dynamic character controller as compared with the regular character controller?

Yea syncing physics can be tough, but now that I"ve got it going I can make multiplayer game with a completely physics driven playable character!!

:slight_smile:

Rama

If you give a player full control of their own position, and that is sent to the server / other clients, a client could potentially hack the game and teleport / move to whatever coordinates they want without any restrictions.

http://www.gabrielgambetta.com/fpm1.html

The regular character controller, as far as I know, is kinematic. Meaning that physics objects can’t push it in the normal way that physics objects get pushed around (it may have support for doing that, but if so it’s probably done via the kinematic movement system still).

I might be wrong though, and maybe it’s already using a dynamic character controller? Dunno.

The difference is basically whether or not the collision volume is kinematic or dynamic in the physics sim.

It’s a little hard to explain because UE4 I think fakes a lot of the stuff you don’t get normally with a kinematic character controller, such as being able to be pushed, and not having infinite push force yourself etc.

Have you actually started coding in UE4’s network code?

Epic has protection mechanisms to prevent that.

Every server/client function has to be validated in the compile-time code itself or it won’t run :slight_smile:

:slight_smile:

Rama

Yes the controller I am showing in video is using full physics, not kinematic animation/movement.

That’s the whole point of the video and my algorithm!

Fully replicating player-controlled physics movement! Yay!

:slight_smile:

Rama

Oh, that’s news to me.

I’ve been doing plenty of work with replication and RPCs if that’s what you’re asking, but haven’t heard of anything like this.

Do you know anything about these mechanisms or where I can read about them?

Thanks :slight_smile:

If you look in the C++ at the ShooterGame example you can see how every server function is now marked with WithValidation, and in the CPP you can see how every server/client function must have both _Implementation and _Validate

This is what I am talking about :slight_smile:

Example from my code base


bool AJoyMovement::SERVER_SetJoyMove**_Validate**(EJoyMovement::Type NewJoyMode)
{
	return true;
}

void AJoyMovement::SERVER_SetJoyMove**_Implementation**(EJoyMovement::Type NewJoyMode)
{
	//Already current?
	if(JoyMoveMode == NewJoyMode)
	{
		return;
		//~~~~
	}

//....

Every server/client function must be validated in this way or the UE4 code wont compile :slight_smile:

:slight_smile:

Rama

Yup, but you have to actually validate it.

If your client is setting their position, how would you validate that?

I am using the same exact control setup that Epic uses for movement using a movement component, it is just that I am passing impulses to the physics-simulating mesh instead of to a movement component.

If the issue you are concerned about was a real issue, it would be affecting regular pawn movement just as much as my own system. So see if you hack regular pawn movement, if you are that concerned about this topic :slight_smile:

In the code base it is this function that is called from the local player and sent server side eventually after being processed in the CharacterMovementComponent



// add movement in that direction
AddMovementInput(Direction, Value);


See Pawn.h and PawnMovementComponent.h for more info

The only difference in my code is that I am calling AddImpulse instead of AddMovementInput.

The tricky part was making the results of AddImpulse replicate :slight_smile:

The end user cannot set their location directly, they have to use AddImpulse the same way regular movement is done with AddMovementInput.

I am not making a game where I am concerned about cheating, in my game that makes no sense since it has a built-in multiplayer editor, and you are playing cooperatively as friends.

We make the world together, cooperatively, and then battle the AI !

:slight_smile:

Rama

what is a “proxy”?

does the client have set simulate physics on or all physics is handled by server?

you did this with c++ code project, is this possible to do the same in blueprint?