Jump to content
  • Advertisement
Sign in to follow this  
newtechnology

Best way to determine and replicate aimoffsets to other clients?

This topic is 561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's what I currently do -
 

1. Ray cast from camera's center (crosshair) 

[attachment=35484:Capture2.PNG]

[attachment=35485:Capture.PNG]

2a. If the hit was successful, then I make a vector from muzzle location to the point where it hit (PointHit - MuzzleLocation)
[attachment=35486:Capture.PNG]

3. Now I use "Find Look at Rotation" and interpolate from current aim pitch (the pitch rotation of where player is currently aiming) to the pitch rotation of where he should aim and then I set the current pitch to the result of FInterpTo and then I replicate it to other clients
[attachment=35487:Capture.PNG]

4. When the other clients receive this update of aim pitch, I again interpolate from the current aim pitch to the received aim pitch otherwise it's jittery
[attachment=35488:Capture.PNG]

(BP AimPitch is used inside Animation blueprint to drive aimoffsets while AimOffsets is just the replicated variable through which it receives update)

 

2b. Now If the hit was not successful, I make a vector from camera's center to infinity (i.e ResultantVector = cameraLocation + cameraForwardVectorNormalized * 15000)
and then I do the same steps done above

The disadvantage of this is sudden jerk at times when the RayCast is successfully hitting some geometry and all of a sudden the player aims somewhere where there is no geometry so raycast fails

note - you don't see this jerk in first person, only other people who see you in third person see this jerk because this aimoffsets are only applied to the third person character and while in first person (where you see different view model), you don't see third person character because Third Person Character has (OwnerNoSee = true) and First Person Character has (OnlyOwnerSee = true)

(I hope it was not too confusing :P )

I'd like to know if there is any better way to achieve this. 

 

Offtopic - 

There is no "UE4" Topic prefix available in scroll list
[attachment=35489:offtopic.PNG]

Edited by newtechnology

Share this post


Link to post
Share on other sites
Advertisement

Turns out that unreal already has a system for this kind of thing (Saw it in Shootergame Sample).

 

There is a RemoteViewPitch (byte) replicated variable which contains pitch rotation (compressed into 1 byte) for remote clients in Pawn.h

 

 
FRotator ABaseCharacter::GetAimOffsets() const
{
const FVector AimDirWS = GetBaseAimRotation().Vector();
const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(AimDirWS);
const FRotator AimRotLS = AimDirLS.Rotation();
 
return AimRotLS;
}
Edited by newtechnology

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!