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 basketball bounces infinitely in built server

I have a physics basketball that I am trying to add to a multiplayer game. The basketball works as expected when playing the game in the editor with Run Dedicated Server turned on. However, when I try to use the basketball in a built server as opposed to the dedicated server, the basketball bounces infinitely. This is not the outcome that I want, as not only does it look unrealistic but it also costs a lot of CPU.

The basketball inherits from a CProp class. The transform of each prop is replicated over the server. The Tick function interacts with the transform like so:

 void ACProp::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
     
     if(Role < ROLE_Authority)
     {
         // Smoothly interpolate towards updated position
         TimeSincePreviousReplication += DeltaTime;
 
         if (bIsDynamicProp)
         {
             SetActorTransform(Collision->GetComponentTransform());
         }
         else
         {
             auto NewLocation = ReplicatedTransform.GetLocation();
             auto NewRotation = ReplicatedTransform.GetRotation();
             SetActorLocationAndRotation(NewLocation, NewRotation);
         }
     }
     else
     {
         if(Collision)
             ReplicatedTransform = Collision->GetComponentTransform();
     }
 }

And here is the transform's OnRep function:

 void ACProp::OnRep_ReplicatedTransform()
 {
     // Get velocity
     auto Dist = FVector(PreviousTransform.GetLocation() - ReplicatedTransform.GetLocation()).Size();
     MovementSpeed = Dist / TimeSincePreviousReplication;
 
     PreviousTransform = ReplicatedTransform;
     TimeSincePreviousReplication = 0.f;
 }


The basketball also has its own Blueprint functionality to handle physics (since it is the only object in the game so far that uses physics). Here is the function for picking up the ball: alt text

Function for throwing the ball: alt text

I have tried adding a Multicast RPC to the basketball which was executed every tick, but that didn't work either. The function looked like this: alt text

I would deeply appreciate any advice that you all are able to give me, as this issue has plagued me for the better part of a week. Please let me know if anything I have mentioned in this question is unclear, and I look forward to hearing from you all soon! :)

Product Version: UE 4.19
Tags:
more ▼

asked Sep 25 '18 at 08:29 PM in C++ Programming

avatar image

Klerick
6 1 5

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

1 answer: sort voted first

I actually solved my own problem! As it turns out, the issue wasn't replication over the network; all it took to solve the infinite bouncing was adjusting the Restitution value on the Physics Material that I was using from 0.95 down to 0.9. sad trumpets Either way, I'm very glad that I solved this, and I hope someone comes across this and finds it helpful!

more ▼

answered Oct 01 '18 at 03:15 PM

avatar image

Klerick
6 1 5

(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