x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Physics, FPS and Multiplayer

Hey There,

I've really be scratching my head at this for days now and i feel iv tried every solution I've found online without any success.

I am creating a physics based game which the player can control a sphere pawn and roll around and do stuff. The way i am moving the pawn is by adding force to it which is a set number, multiplied by the InputAxis, with the function being bound onto the InputPlayerComponent. It is the same setup as the third person template except im using AddForce.

From the information i have found online, AddForce already takes into consideration the DeltaTimeSeconds therefore, you should NOT multiply the force by it, which i am not doing. When testing this in a single player session, everything works expected. 30, 60, or 120 FPS the balls rolls at the same rate. Perfect.

However, When joining a multiplayer session, the ball rolls much faster at higher FPS and much slower at Lower FPS. When multiplying by DeltaSeconds i get the reversed effect. I have enabled SubStepping which doesn't seem to do anything. I have also modified the engine code and implemented a Fixed Timestep which just causes the ball to hop around and still doesn't prevent FPS from dictating the speed.

Is there any solution to this problem?

I can post C++ Code if needed.

Product Version: UE 4.20
Tags:
more ▼

asked Aug 30 '18 at 01:55 AM in C++ Programming

avatar image

Shadow Nightmare
8 1 3

avatar image ortroll Aug 30 '18 at 08:44 AM

I'm pretty much sure that AddForce is not the cause of your problem. How did you setup your replication?

avatar image Shadow Nightmare Aug 30 '18 at 12:01 PM

Hey,

I have all the movement functions running on the server side. Physics is also enabled on the server side only and disabled for the clients. In the Tick Function i then have a custom function which sets the clients transform to whatever the server has calculated it should be.

Edit: After this comment i went and disabled the tick function and enabled replication on the sphere mesh and the same issue still applies. I tested a little bit more and im pretty certain its how many times the client is calling the move functions. Since i have the move function bound to the PlayerInputComponent, its getting called more often at higher frame rates. Meaning the amount of times AddForce is being called at higher fps is crazy high. I'm not sure if i can limit this though.

Edit 2: I also forgot to mention that this issue only applies to the clients. The listen servers physics still function correctly regardless of the FPS.

Edit 3: The issue only seems to happen on Standalone version of the game. Using PIE seems to have expected results.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

I have a suggestion that this happens because SetWorldLocation also affects the velocity, and the way it changes really depends on delta time, thus on fps.Try to pass velocity alongside with location and call SetWorldLocation with 'Teleport' flag (and keep physics enabled on clients, to get more fluid image). Also, I would rather call AddForce in tick, controlled by replicated bool variable that tells if player wants to move. This way I'm sure that my move speed is not affected by network quality.


Here is the demo (done in blueprints, UE 4.20)

https://drive.google.com/file/d/10hAjELv9KRmzZa6vQk98PK3iTvrJ7w-q/view?usp=sharing

Could you please test it and tell if it has those problems.

more ▼

answered Aug 30 '18 at 09:47 PM

avatar image

ortroll
142 1 5 9

avatar image Shadow Nightmare Aug 31 '18 at 02:02 AM

Hey there!

Thanks for setting this project up for me its actually super helpful. After tested it the same way i did with mine, Yours seem to work flawlessly.

Its really late at the time of posting this but i wanted to just give you a quick update.

Tomorrow, I'll go back and re haul my c++ project to see if i can get it working using the same approach you have. I've probably littered my code through countless changes and made it worse and worse overtime.

Side note: I noticed you used a player controller, something i completely overlooked as i did all the movement within the pawn. Maybe this has an effect?

avatar image ortroll Aug 31 '18 at 09:00 AM

Using player controller is more of consistency thing. There could be numerous reasons, why it worked like that. This could be dropped network packets, or misuse of 'SetWorldLocation'.

P.S. don't forget to mark this as answered :D

avatar image Shadow Nightmare Aug 31 '18 at 02:54 PM

Re created your setup on my own project in blueprints and once again worked flawlessly. There was a little bit of jitter on the client side when playing online but i managed to fix that by using a little bit of interpolation.

Can't thank you enough for solving this. Thanks again for sending over the project and helping me out <3

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question