Add vehicle velocity prediction/acceleration
This commit is contained in:
@ -341,6 +341,7 @@ namespace RageCoop.Client
|
||||
v.ThrottlePower=packet.ThrottlePower;
|
||||
v.BrakePower=packet.BrakePower;
|
||||
v.Velocity=packet.Velocity;
|
||||
v.Acceleration=packet.Acceleration;
|
||||
v.RotationVelocity=packet.RotationVelocity;
|
||||
v.DeluxoWingRatio=packet.DeluxoWingRatio;
|
||||
v.LastSynced=Main.Ticked;
|
||||
|
@ -93,11 +93,14 @@ namespace RageCoop.Client
|
||||
SteeringAngle = veh.SteeringAngle,
|
||||
Position = veh.PredictPosition(),
|
||||
Quaternion=veh.ReadQuaternion(),
|
||||
Velocity = veh.Velocity,
|
||||
RotationVelocity=veh.RotationVelocity,
|
||||
ThrottlePower = veh.ThrottlePower,
|
||||
BrakePower = veh.BrakePower,
|
||||
};
|
||||
var velo = veh.Velocity;
|
||||
packet.Acceleration = (velo-v.LastVelocity)*1000/v.LastSentStopWatch.ElapsedMilliseconds;
|
||||
packet.Velocity=(v.LastVelocity = velo) + packet.Acceleration*Latency;
|
||||
v.LastSentStopWatch.Restart();
|
||||
if (packet.Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering)) { packet.DeluxoWingRatio=v.MainVehicle.GetDeluxoWingRatio(); }
|
||||
if (full)
|
||||
{
|
||||
|
@ -56,10 +56,10 @@ namespace RageCoop.Client
|
||||
|
||||
private byte[] _lastVehicleColors = new byte[] { 0, 0 };
|
||||
private Dictionary<int, int> _lastVehicleMods = new Dictionary<int, int>();
|
||||
private bool _lastTouchingPlayer = false;
|
||||
#endregion
|
||||
|
||||
#region -- CRITICAL STUFF --
|
||||
internal Vector3 Acceleration { get; set; }
|
||||
internal Vector3 RotationVelocity { get; set; }
|
||||
internal float SteeringAngle { get; set; }
|
||||
internal float ThrottlePower { get; set; }
|
||||
@ -352,20 +352,24 @@ namespace RageCoop.Client
|
||||
}
|
||||
LastUpdated=Main.Ticked;
|
||||
}
|
||||
float _elapsed;
|
||||
Vector3 _predictedVel;
|
||||
Vector3 _predictedPos;
|
||||
void DisplayVehicle(bool touching)
|
||||
{
|
||||
// predict velocity/position
|
||||
_elapsed = Networking.Latency+0.001f*LastSyncedStopWatch.ElapsedMilliseconds;
|
||||
_predictedVel = Velocity+Acceleration*_elapsed;
|
||||
_predictedPos = Position+_elapsed*(LastVelocity+_predictedVel)/2;
|
||||
LastVelocity=_predictedVel;
|
||||
var current = MainVehicle.ReadPosition();
|
||||
var predicted = Position+Velocity*(Networking.Latency+0.001f*LastSyncedStopWatch.ElapsedMilliseconds);
|
||||
var dist = current.DistanceTo(Position);
|
||||
var cali = (touching ? 0.001f : 1)*dist*(predicted - current);
|
||||
var cali = dist*(_predictedPos - current);
|
||||
// new LemonUI.Elements.ScaledText(new System.Drawing.PointF(50, 50), dist.ToString()).Draw();
|
||||
|
||||
if (dist<8)
|
||||
{
|
||||
if (!touching)
|
||||
{
|
||||
MainVehicle.Velocity = Velocity+cali;
|
||||
}
|
||||
MainVehicle.Velocity = _predictedVel+cali;
|
||||
if (IsFlipped)
|
||||
{
|
||||
MainVehicle.Quaternion=Quaternion.Slerp(MainVehicle.ReadQuaternion(), Quaternion, 0.5f);
|
||||
@ -376,7 +380,7 @@ namespace RageCoop.Client
|
||||
Vector3 calirot = GetCalibrationRotation();
|
||||
if (calirot.Length()<50)
|
||||
{
|
||||
MainVehicle.RotationVelocity = (touching ? 0.001f : 1)*(RotationVelocity+calirot*0.2f);
|
||||
MainVehicle.RotationVelocity = RotationVelocity+calirot*0.2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -387,8 +391,8 @@ namespace RageCoop.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
MainVehicle.Position=predicted;
|
||||
MainVehicle.Velocity=Velocity;
|
||||
MainVehicle.Position=_predictedPos;
|
||||
MainVehicle.Velocity=_predictedVel;
|
||||
MainVehicle.Quaternion=Quaternion;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace RageCoop.Core
|
||||
// public Vector3 Rotation { get; set; }
|
||||
|
||||
public Vector3 Velocity { get; set; }
|
||||
public Vector3 Acceleration { get; set; }
|
||||
|
||||
public Vector3 RotationVelocity { get; set; }
|
||||
|
||||
@ -67,7 +68,7 @@ namespace RageCoop.Core
|
||||
#region PacketToNetOutGoingMessage
|
||||
message.Write((byte)PacketType.VehicleSync);
|
||||
|
||||
List<byte> byteArray = new List<byte>();
|
||||
List<byte> byteArray = new List<byte>(100);
|
||||
|
||||
byteArray.AddInt(ID);
|
||||
byteArray.AddInt(OwnerID);
|
||||
@ -75,6 +76,7 @@ namespace RageCoop.Core
|
||||
byteArray.AddVector3(Position);
|
||||
byteArray.AddQuaternion(Quaternion);
|
||||
byteArray.AddVector3(Velocity);
|
||||
byteArray.AddVector3(Acceleration);
|
||||
byteArray.AddVector3(RotationVelocity);
|
||||
byteArray.AddFloat(ThrottlePower);
|
||||
byteArray.AddFloat(BrakePower);
|
||||
@ -192,6 +194,8 @@ namespace RageCoop.Core
|
||||
// Read velocity
|
||||
Velocity =reader.ReadVector3();
|
||||
|
||||
Acceleration=reader.ReadVector3();
|
||||
|
||||
// Read rotation velocity
|
||||
RotationVelocity=reader.ReadVector3();
|
||||
|
||||
|
Reference in New Issue
Block a user