chore: improved client paddle prediction
This commit is contained in:
		@@ -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)
 | 
					    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;
 | 
					        isUpPressed = packet.IsUpPressed;
 | 
				
			||||||
        isDownPressed = packet.IsDownPressed;
 | 
					        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);
 | 
					        physicsEngine2D.StepIndividual(rigidBody, sender.Ping);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Vector2D localToServerPosition = Transform.Position.FromTo(packet.Position);
 | 
				
			||||||
 | 
					        networkTween = Transform.TweenPositionAdditive(tweenManager, .1f, localToServerPosition);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public class PaddleKeyStatePacket : IEntityNetworkPacket
 | 
					    public class PaddleKeyStatePacket : IEntityNetworkPacket
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user