Compare commits

...

3 Commits

Author SHA1 Message Date
MrGadget
dc7a3c750f
Merge 2508cfd618 into 451c297a43 2024-11-13 03:12:52 +02:00
miwarnec
451c297a43 NTHybrid: fix name and Unity 2019 support
Some checks failed
Main / Run Unity Tests (push) Has been cancelled
Main / Delete Old Workflow Runs (push) Has been cancelled
Main / Semantic Release (push) Has been cancelled
2024-11-11 16:58:42 +01:00
MrGadget
2508cfd618 feat(NetworkTranformBase): Provide velocity and angular velocity 2024-09-30 08:41:02 -04:00
3 changed files with 28 additions and 3 deletions

View File

@ -119,6 +119,23 @@ public uint sendIntervalMultiplier
protected double timeStampAdjustment => NetworkServer.sendInterval * (sendIntervalMultiplier - 1); protected double timeStampAdjustment => NetworkServer.sendInterval * (sendIntervalMultiplier - 1);
protected double offset => timelineOffset ? NetworkServer.sendInterval * sendIntervalMultiplier : 0; protected double offset => timelineOffset ? NetworkServer.sendInterval * sendIntervalMultiplier : 0;
[Header("Velocity")]
[ReadOnly, SerializeField] Vector3 _velocity;
[ReadOnly, SerializeField] Vector3 _angVelocity;
public Vector3 velocity
{
get => _velocity;
internal set => _velocity = value;
}
public Vector3 angVelocity
{
get => _angVelocity;
internal set => _angVelocity = value;
}
// debugging /////////////////////////////////////////////////////////// // debugging ///////////////////////////////////////////////////////////
[Header("Debug")] [Header("Debug")]
public bool showGizmos; public bool showGizmos;
@ -263,6 +280,14 @@ protected virtual void Apply(TransformSnapshot interpolated, TransformSnapshot e
// -> but simply don't apply it. if the user doesn't want to sync // -> but simply don't apply it. if the user doesn't want to sync
// scale, then we should not touch scale etc. // scale, then we should not touch scale etc.
// Calculate the velocity and angular velocity for the object
// These can be used to drive animations or other behaviours
if (!isOwned)
{
velocity = (transform.position - interpolated.position) / Time.deltaTime;
angVelocity = (transform.rotation.eulerAngles - interpolated.rotation.eulerAngles) / Time.deltaTime;
}
// interpolate parts // interpolate parts
if (syncPosition) SetPosition(interpolatePosition ? interpolated.position : endGoal.position); if (syncPosition) SetPosition(interpolatePosition ? interpolated.position : endGoal.position);
if (syncRotation) SetRotation(interpolateRotation ? interpolated.rotation : endGoal.rotation); if (syncRotation) SetRotation(interpolateRotation ? interpolated.rotation : endGoal.rotation);

View File

@ -367,7 +367,7 @@ protected virtual void OnClientToServerDeltaSync(byte baselineTick, Vector3 posi
bufferSizeLimit, bufferSizeLimit,
new TransformSnapshot( new TransformSnapshot(
timestamp, // arrival remote timestamp. NOT remote time. timestamp, // arrival remote timestamp. NOT remote time.
Time.timeAsDouble, NetworkTime.localTime, // Unity 2019 doesn't have Time.timeAsDouble yet
position, position,
rotation, rotation,
scale scale
@ -710,8 +710,8 @@ protected virtual void OnServerToClientDeltaSync(byte baselineTick, Vector3 posi
clientSnapshots, clientSnapshots,
bufferSizeLimit, bufferSizeLimit,
new TransformSnapshot( new TransformSnapshot(
timestamp, // arrival remote timestamp. NOT remote time. timestamp, // arrival remote timestamp. NOT remote time.
Time.timeAsDouble, NetworkTime.localTime, // Unity 2019 doesn't have Time.timeAsDouble yet
position, position,
rotation, rotation,
scale scale