🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Best way to determine and replicate aimoffsets to other clients?

Started by
0 comments, last by 215648 7 years, 2 months ago

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]

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;
}

This topic is closed to new replies.

Advertisement