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"

Modify Projectile Velocity On Client

I am currently spawning my projectiles on the server only and replicating them and their movement to the clients. alt text

However, when I modify the projectiles velocity on the server post spawn it doesn't get replicated to the client. This is obviously because the movement component's velocity is not replicated.

This results in jerky projectile movement. Since they are moving at different velocities on the server and client.

I know that I could solve this by creating a new replicated property on my Actor or using a RPC.

However, this seems like something that should be built in since the movement is being replicated.

So I dug into it and found FRepMovement. I figured that setting it's LinearVelocity on the server would fix the issue I'm having with the velocity not being changed on the client. However it did not. Is there really no built in way to update the velocity of the projectile on the server only and have the client get it as well?

 void UFPSAbility::SpawnProjectile(FName SocketName, FVector Location, FRotator RotationOverride)
 {
     if (ProjectileClass)
     {
         if (Character)
         {
             // Spawn the projectile
             UWorld* const World = Character->GetWorld();
             if (World)
             {
                 FActorSpawnParameters SpawnParams;
                 SpawnParams.Instigator = Character;
                 SpawnParams.Owner = Character;
                 AFPSAbilityProjectile* Projectile = World->SpawnActor<AFPSAbilityProjectile>(ProjectileClass, Location, RotationOverride, SpawnParams);
                 if (Projectile)
                 {
                     Projectile->Instigator = Character;
                     // Change the velocity of the projectile based on the chargeup
                     if (MaxChargeUpTime > 0.f)
                     {
                         // Pass the chargeup power to the projectile and let it handle it from here
                         Projectile->SetChargeUpPower(CurrentChargeUpTime / MaxChargeUpTime);
                     }
                 }
             }
         }
     }
 }
 
 void AFPSAbilityProjectile::SetChargeUpPower(float InChargeUpPower)
 {
     ChargeUpPower = InChargeUpPower;
 
     if (bChargeUpAffectsVelocity)
     {
         if (MovementComp)
         {
             // THIS NEEDS TO BE SET ON THE CLIENT TOO, BECAUSE OF CLIENTSIDE PREDICTION
             float Speed = FMath::Max(MinSpeed, MovementComp->InitialSpeed * ChargeUpPower);
             MovementComp->Velocity = GetActorForwardVector() * Speed;
             ReplicatedMovement.LinearVelocity = MovementComp->Velocity;
         }
     }
 }


Product Version: UE 4.12
Tags:
rep.png (13.9 kB)
more ▼

asked Oct 11 '16 at 02:56 PM in C++ Programming

avatar image

erebel55
410 44 47 68

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I've encountered this problem here many times and I think the answer is no. The solution you proposed with the new replicated property is a good solution or you could also just set it twice every time, one on the client before calling the server and one on the server and viceversa. I agree with you, it seems intuitive to have a movement component replicated by default since location and velocity are already replicated by default, but I don't know why it isn't like that.

more ▼

answered Oct 11 '16 at 03:57 PM

avatar image

MacDx
620 17 10 34

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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