Improved vehicle sync

This commit is contained in:
sardelka9515
2022-11-20 15:55:11 +08:00
parent 78f0dfaebb
commit 7dec978e9a
5 changed files with 35 additions and 38 deletions

View File

@ -123,7 +123,7 @@ namespace RageCoop.Client
}; };
return; return;
} }
BaseScript.OnStart(); BaseScript.OnStart();
SyncedPedsGroup = World.AddRelationshipGroup("SYNCPED"); SyncedPedsGroup = World.AddRelationshipGroup("SYNCPED");
Game.Player.Character.RelationshipGroup.SetRelationshipBetweenGroups(SyncedPedsGroup, Relationship.Neutral, Game.Player.Character.RelationshipGroup.SetRelationshipBetweenGroups(SyncedPedsGroup, Relationship.Neutral,
@ -217,7 +217,7 @@ namespace RageCoop.Client
{ {
return; return;
} }
else if (!_gameLoaded && (_gameLoaded = true)) if (!_gameLoaded && (_gameLoaded = true))
{ {
#if !NON_INTERACTIVE #if !NON_INTERACTIVE
Notification.Show(NotificationIcon.AllPlayersConf, "RAGECOOP", "Welcome!", Notification.Show(NotificationIcon.AllPlayersConf, "RAGECOOP", "Welcome!",

View File

@ -1,4 +1,7 @@
using System.Reflection; 
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources; using System.Resources;
// General Information // General Information
@ -12,7 +15,8 @@ using System.Resources;
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Version informationr( // Version information
[assembly: AssemblyVersion("1.6.0.0")] [assembly: AssemblyVersion("1.6.0.1")]
[assembly: AssemblyFileVersion("1.6.0.0")] [assembly: AssemblyFileVersion("1.6.0.1")]
[assembly: NeutralResourcesLanguageAttribute("en-US")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )]

View File

@ -33,7 +33,7 @@ using System.Resources;
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Version informationr( // Version information
[assembly: AssemblyVersion("<#= this.major #>.<#= this.minor #>.<#= this.revision #>.<#= this.build #>")] [assembly: AssemblyVersion("<#= this.major #>.<#= this.minor #>.<#= this.revision #>.<#= this.build #>")]
[assembly: AssemblyFileVersion("<#= this.major #>.<#= this.minor #>.<#= this.revision #>.<#= this.build #>")] [assembly: AssemblyFileVersion("<#= this.major #>.<#= this.minor #>.<#= this.revision #>.<#= this.build #>")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )] [assembly: NeutralResourcesLanguageAttribute( "en-US" )]

View File

@ -59,7 +59,11 @@ namespace RageCoop.Client
internal bool HasRoof; internal bool HasRoof;
internal bool IsSubmarineCar; internal bool IsSubmarineCar;
internal bool IsDeluxo; internal bool IsDeluxo;
internal bool IsTrain;
internal Vector3 TopExtent;
internal Vector3 FrontExtent;
internal Vector3 LeftExtent;
internal Vector3 RightExtent;
#endregion #endregion
#region PRIVATE #region PRIVATE

View File

@ -11,24 +11,10 @@ namespace RageCoop.Client
/// </summary> /// </summary>
public partial class SyncedVehicle : SyncedEntity public partial class SyncedVehicle : SyncedEntity
{ {
/// <summary>
/// VehicleSeat,ID
/// </summary>
internal override void Update() internal override void Update()
{ {
#if DEBUG_VEH
foreach(var s in _predictedTrace)
{
World.DrawMarker(MarkerType.DebugSphere, s, default, default, new Vector3(0.3f, 0.3f, 0.3f), Color.AliceBlue);
}
foreach (var s in _orgTrace)
{
World.DrawMarker(MarkerType.DebugSphere, s, default, default, new Vector3(0.3f, 0.3f, 0.3f), Color.Orange);
}
#endif
// Check if all data available
// Check if all data avalible
if (!IsReady || Owner == null) return; if (!IsReady || Owner == null) return;
// Check existence // Check existence
@ -174,10 +160,9 @@ namespace RageCoop.Client
{ {
_predictedPosition = Predict(Position); _predictedPosition = Predict(Position);
var current = MainVehicle.ReadPosition(); var current = MainVehicle.ReadPosition();
var dist = current.DistanceTo(_predictedPosition); var distSquared = current.DistanceToSquared(_predictedPosition);
var cali = dist * (_predictedPosition - current); var cali = _predictedPosition - current + 0.5f * (Velocity - MainVehicle.Velocity);
if (Velocity.Length() < 0.1) cali *= 10; if (distSquared > 10 * 10)
if (dist > 10)
{ {
MainVehicle.Position = _predictedPosition; MainVehicle.Position = _predictedPosition;
MainVehicle.Velocity = Velocity; MainVehicle.Velocity = Velocity;
@ -185,17 +170,15 @@ namespace RageCoop.Client
return; return;
} }
if (dist > 0.03) MainVehicle.Velocity = Velocity + cali; // Calibrate rotation
var curQuat = MainVehicle.Quaternion;
MainVehicle.ApplyForce(Quaternion * TopExtent - curQuat * TopExtent, TopExtent);
MainVehicle.ApplyForce(Quaternion * FrontExtent - curQuat * FrontExtent, FrontExtent);
Vector3 calirot; // Calibrate position
if (IsFlipped || (calirot = GetCalibrationRotation()).Length() > 50) if (distSquared < 0.03 * 0.03) return;
{ if (!IsTrain && distSquared > 20 * 20) MainVehicle.Velocity = Velocity + cali;
MainVehicle.Quaternion = Quaternion.Slerp(MainVehicle.ReadQuaternion(), Quaternion, 0.5f); else MainVehicle.ApplyForce(cali);
MainVehicle.RotationVelocity = RotationVelocity;
return;
}
MainVehicle.RotationVelocity = RotationVelocity + calirot * 0.2f;
} }
private Vector3 GetCalibrationRotation() private Vector3 GetCalibrationRotation()
@ -273,6 +256,12 @@ namespace RageCoop.Client
HasRoof = MainVehicle.HasRoof; HasRoof = MainVehicle.HasRoof;
IsSubmarineCar = MainVehicle.IsSubmarineCar; IsSubmarineCar = MainVehicle.IsSubmarineCar;
IsDeluxo = MainVehicle.Model == 1483171323; IsDeluxo = MainVehicle.Model == 1483171323;
IsTrain = MainVehicle.IsTrain;
var (rbl, ftr) = MainVehicle.Model.Dimensions;
FrontExtent = new Vector3(0, ftr.Y, 0);
TopExtent = new Vector3(0, 0, ftr.Z);
LeftExtent = new Vector3(rbl.X, 0, 0);
RightExtent = new Vector3(ftr.X, 0, 0);
} }
/// <summary> /// <summary>