chore: improved client paddle prediction
This commit is contained in:
parent
80725f454f
commit
9302c7e867
@ -88,16 +88,19 @@ public class Paddle(Keys Up, Keys Down, float High, float Low, float Speed) : Be
|
||||
|
||||
public void OnClientPacketArrived(IConnection sender, PaddleKeyStatePacket packet)
|
||||
{
|
||||
if (packet.IsDownPressed || packet.IsUpPressed) // Check if the server paddle is moving
|
||||
if (isDownPressed == packet.IsDownPressed && isUpPressed == packet.IsUpPressed) // Check if we are the ones giving the inputs
|
||||
return;
|
||||
|
||||
physicsEngine2D.StepIndividual(rigidBody, -sender.Ping);
|
||||
|
||||
isUpPressed = packet.IsUpPressed;
|
||||
isDownPressed = packet.IsDownPressed;
|
||||
|
||||
Vector2D localToServerPosition = Transform.Position.FromTo(packet.Position);
|
||||
if (localToServerPosition.MagnitudeSquared < 1f)
|
||||
networkTween = Transform.TweenPositionAdditive(tweenManager, .25f, localToServerPosition);
|
||||
else
|
||||
Transform.Position = packet.Position;
|
||||
|
||||
physicsEngine2D.StepIndividual(rigidBody, sender.Ping);
|
||||
|
||||
Vector2D localToServerPosition = Transform.Position.FromTo(packet.Position);
|
||||
networkTween = Transform.TweenPositionAdditive(tweenManager, .1f, localToServerPosition);
|
||||
}
|
||||
|
||||
public class PaddleKeyStatePacket : IEntityNetworkPacket
|
||||
|
Loading…
x
Reference in New Issue
Block a user