When Adding Force to the Client from the Server, why would the force applied be different?

I am using two different Add Force nodes. One applies force for horizontal movement and jumping, the other applies force for custom gravity. The problem is that it seems that movement is constrained by the gravity applied to it (I’ve checked that both Server and Client players have -980 gravitational force being applied at run-time). Even with the same gravity, the server is able to move as intended, but the client is only able to move very slowly.

I have tried running the NetApplyForce only (movement force), and both Client and Server (Listen Server) move as intended. With that I can surmise that the force being applied by NetApplyForce is the same for both Client and Server players.

If I turn on the Dedicated Server option, both clients move normally (with NetApplyGrav being executed). There only seems to be an issue when using a Listen Server.

If you need more information from me, please don’t hesitate to ask.

Hmm I’m not sure if this is the problem, but I’ve dealt with this kind of stuff before , if you are executing these functions every frame and you do this on a listen server, the window acting as the server calls this function every tick without problem but the client window has to wait for the call to arrive and so several ticks might have passed. So this would explain why the client is moving slower than the server.

So, just a couple of questions to help me understand your problem better.

When are these functions being executed?

Do these functions have the Reliable option checked?

On a side note. I think you really don’t need the authority checks there because those nodes say “Execute on Server” meaning that you are already on the server when those functions execute and thus making the authority check redundant. I might be wrong though.

When are these functions being executed?

Using a Sequence, the NetApplyForce event is being called before the NetApplyGrav event is. I basically use the events in place of the AddForce function.

Do these functions have the Reliable option checked?

Yes

I can try not using the Authority checks, maybe that could be causing what you’ve described.

MacDx,

I hope you can still help me. I am still stuck on this, and I did some testing. I believe I’ve confirmed that the server player is indeed running its tick twice as fast. It seems to be affecting the NetApplyGrav specifically, since that uses a tick to cast a ray which gives me the normal of the surface I’m standing on. I’ve tested with a set gravity (Z: -980), but that made no difference.

Sure!

Let’s see. So I think maybe the problem is how the code is structured. Do the ApplyGravity function really needs to be server sided? Why not doing it locally (normal function executed by every actor that is locally controlled instead of a server one), and just let the player position replicate accordingly?

It would be great if you could show some more code and what are the blueprint classes you are using, so I can get a better idea of what’s happening.

Just so you know I’m using a Pawn (the default gravity isn’t being used). I’d also like to note that I tried just using the default gravity (disabled my implementation) and it seemed to work fine. Here are my gravity blueprint nodes:

84683-gravity1.png

Ok. Why dont you try something like this:

Instead of using NetApplyGrav use a normal function instead.

What I did here is make Gravity a replicated variable. Also I added an authority check so only server actors do the ray cast and set gravity. Also apply gravity is a normal function not a network one.

Edit: Also forgot to mention, use a IsLocallyControlled check so gravity is only applied to actors that are being controlled by a player, this way you apply force locally using the gravity value replicated by the server.

And just be sure that replicated movement and replicates are checked on your actor replication settings.

84693-replication.png

ApplyGravity would look like this:

The only problem I can see is, wouldn’t the authority check keep the client’s actor from being able to have it’s own (different) gravitational direction? My game is going to pretty much require that all players be able walk on walls and the like.

What do you mean different gravitational direction, different from what?

Edit: I think I get you now. My answer is, no it wouldn’t, you said this blueprint is a pawn actor right? so every single actor has it’s own gravity variable. All what the authority check does is make sure this gravity variable is only set by the server, based on the trace done by the server version of your actor.

Thank you so much! I took a good look at what you suggested and figured out that if I used IsLocallyControlled, I could solve my problem. I didn’t need to apply the gravity locally.

Your help has been very valuable!

Glad I could help :slight_smile: !!