• Advertisement
Sign in to follow this  

Best way to determine and replicate aimoffsets to other clients?

Recommended Posts

Here's what I currently do -

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



2a. If the hit was successful, then I make a vector from muzzle location to the point where it hit (PointHit - MuzzleLocation)

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

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

(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

Edited by newtechnology

Share this post

Link to post
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement