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"

Rotation Replication Wrong

Hello,

I'm trying achieve placing a particle system in the location the player is looking, it works good but the rotation angles are ignored during replication - it seems to only take into account the location vectors. If somebody can look at the code and tell me what I'm doing wrong I'd appreciate it.

 void AWepAttach_Sights::dostuff()
 {
     TArray<AActor*> ignoredActors;
     ignoredActors.Add(this);
     ignoredActors.Add(GetOwner());
     ignoredActors.Add(MyPawn);
 
     FHitResult Hit(ForceInit);
 
     static FName LaserTrace = FName(TEXT("LaserTrace"));
     FCollisionQueryParams RV_TraceParams(LaserTrace, true, GetOwner());
 
     RV_TraceParams.bReturnPhysicalMaterial = false;
     RV_TraceParams.bTraceComplex = false;
     RV_TraceParams.bTraceAsyncScene = true;
     RV_TraceParams.AddIgnoredActors(ignoredActors);
 
     const FRotator viewRot = MyPawn->GetViewRotation().GetNormalized();
     const FVector StartDir = MyPawn->GetPawnViewLocation();
     const FVector Direction = MyPawn->GetPawnViewLocation() + FRotationMatrix(viewRot).GetScaledAxis(EAxis::X) * 2000;
 
     GetWorld()->LineTraceSingleByChannel(Hit, StartDir, Direction, ECC_Visibility, RV_TraceParams);
 
     if (Hit.bBlockingHit)
     {
 #ifdef DEBUG_MODE
         DrawDebugLine(GetWorld(), StartDir, Direction, FColor(255, 0, 0), false, 2.0f, 0, 3.0f);
 #endif    
     }
 
     if (Role == ROLE_AutonomousProxy)
     {
         Serverdostuff();
     }
 }
 
 bool AWepAttach_Sights::Serverdostuff_Validate()
 {
     return true;
 }
 
 void AWepAttach_Sights::Serverdostuff_Implementation()
 {
     dostuff();
 }
 
Product Version: UE 4.9
Tags:
more ▼

asked Jan 19 '16 at 01:35 PM in C++ Programming

avatar image

BannockUK
13 2 5 10

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

1 answer: sort voted first

Are you saying that the rotation of your pawn, on the client, is not being replicated to the server, even though you've set the rotation variable to replicate?

more ▼

answered Jan 19 '16 at 01:39 PM

avatar image

TTaM
1.7k 79 28 81

avatar image BannockUK Jan 19 '16 at 01:42 PM

Sorry, should have worded it better. Yes that's what I'm saying, at least I'm assuming I've set the rotation variable to replicate.

avatar image TTaM Jan 19 '16 at 01:47 PM

Under no circumstances do variables replicate from the client to the server.

To set a variable to replicate (from server to client) you have to marked it as Replicated or ReplicatedUsing = function in its UPROPERTY macro and then add it to the GetLifetimeReplicationProperties() function.

The character movement component should update the server, though, if you're using a character. Are you using the ACharacter class?

If not, you have 2 options:

  • Send the location, rotation and so on to the server every tick using an RPC.

  • Send the current look direction as a parameter in your server function.

A warning with that second option, rotator axes are compressed down to bytes when replicated, so they lose a lot of their granularity. If you want accurate rotation, send the pitch and yaw as separate parameters as floats.

avatar image BannockUK Jan 19 '16 at 02:03 PM

While that's some insightful information and I appreciate it, I'm not directly sending a basic variable, I'm asking it to replicate the clients GetViewRotation to the server so that it can set the worldposition of the Particle Component. If the Location is replicating, then it implies that I'm doing the right process, but for some reason the angles are not.

avatar image TTaM Jan 19 '16 at 02:10 PM

How are you doing doing the replication?

avatar image BannockUK Jan 19 '16 at 02:13 PM

The same way Shooter Game does SetRunning or EquipWeapon.

avatar image TTaM Jan 19 '16 at 02:15 PM

Assume that not everyone is familiar with shooter game or has a copy of it set up to look at...

avatar image BannockUK Jan 19 '16 at 02:18 PM

If you look at the code in the first post, the structure of how EquipWeapon for example is done, is in the same form. dostuff(); is then called in Tick.

avatar image TTaM Jan 19 '16 at 02:23 PM

So you've got a server rpc function that sends your location and rotation to the server?

Sorry if I wasn't clear before, but that's what I meant.

(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