mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-17 01:13:05 +00:00
cache ReferenceTransform.GetAttachedOWRigidbody() into ReferenceRigidbody
This commit is contained in:
parent
6fb47ffd35
commit
e119920db9
@ -95,8 +95,8 @@ namespace QSB.JellyfishSync.TransformSync
|
|||||||
var pos = ReferenceTransform.FromRelPos(transform.position);
|
var pos = ReferenceTransform.FromRelPos(transform.position);
|
||||||
AttachedRigidbody.SetPosition(pos);
|
AttachedRigidbody.SetPosition(pos);
|
||||||
AttachedRigidbody.SetRotation(ReferenceTransform.FromRelRot(transform.rotation));
|
AttachedRigidbody.SetRotation(ReferenceTransform.FromRelRot(transform.rotation));
|
||||||
AttachedRigidbody.SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, pos));
|
AttachedRigidbody.SetVelocity(ReferenceRigidbody.FromRelVel(_relativeVelocity, pos));
|
||||||
AttachedRigidbody.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity));
|
AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity));
|
||||||
|
|
||||||
_qsbJellyfish.SetIsRising(_isRising);
|
_qsbJellyfish.SetIsRising(_isRising);
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ namespace QSB.ShipSync.TransformSync
|
|||||||
AttachedRigidbody.SetRotation(targetRot);
|
AttachedRigidbody.SetRotation(targetRot);
|
||||||
}
|
}
|
||||||
|
|
||||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
|
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
|
||||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
|
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
|
||||||
|
|
||||||
SetVelocity(AttachedRigidbody, targetVelocity);
|
SetVelocity(AttachedRigidbody, targetVelocity);
|
||||||
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
||||||
|
@ -72,8 +72,8 @@ namespace QSB.Syncs.Occasional
|
|||||||
var pos = ReferenceTransform.FromRelPos(transform.position);
|
var pos = ReferenceTransform.FromRelPos(transform.position);
|
||||||
AttachedRigidbody.SetPosition(pos);
|
AttachedRigidbody.SetPosition(pos);
|
||||||
AttachedRigidbody.SetRotation(ReferenceTransform.FromRelRot(transform.rotation));
|
AttachedRigidbody.SetRotation(ReferenceTransform.FromRelRot(transform.rotation));
|
||||||
AttachedRigidbody.SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, pos));
|
AttachedRigidbody.SetVelocity(ReferenceRigidbody.FromRelVel(_relativeVelocity, pos));
|
||||||
AttachedRigidbody.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity));
|
AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity));
|
||||||
|
|
||||||
Move();
|
Move();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
|||||||
private Vector3 _prevAngularVelocity;
|
private Vector3 _prevAngularVelocity;
|
||||||
|
|
||||||
public OWRigidbody AttachedRigidbody { get; private set; }
|
public OWRigidbody AttachedRigidbody { get; private set; }
|
||||||
|
public OWRigidbody ReferenceRigidbody { get; private set; }
|
||||||
|
|
||||||
protected abstract OWRigidbody InitAttachedRigidbody();
|
protected abstract OWRigidbody InitAttachedRigidbody();
|
||||||
|
|
||||||
@ -26,6 +27,17 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
|||||||
return AttachedRigidbody ? AttachedRigidbody.transform : null;
|
return AttachedRigidbody ? AttachedRigidbody.transform : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void SetReferenceTransform(Transform referenceTransform)
|
||||||
|
{
|
||||||
|
if (ReferenceTransform == referenceTransform)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.SetReferenceTransform(referenceTransform);
|
||||||
|
ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void UpdatePrevData()
|
protected override void UpdatePrevData()
|
||||||
{
|
{
|
||||||
base.UpdatePrevData();
|
base.UpdatePrevData();
|
||||||
@ -57,8 +69,8 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
|||||||
|
|
||||||
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
|
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
|
||||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
|
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
|
||||||
_relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
|
_relativeVelocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
|
||||||
_relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
|
_relativeAngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ApplyToAttached()
|
protected override void ApplyToAttached()
|
||||||
@ -84,8 +96,8 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
|||||||
AttachedRigidbody.MoveToPosition(positionToSet);
|
AttachedRigidbody.MoveToPosition(positionToSet);
|
||||||
AttachedRigidbody.MoveToRotation(rotationToSet);
|
AttachedRigidbody.MoveToRotation(rotationToSet);
|
||||||
|
|
||||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
|
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
|
||||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
|
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
|
||||||
|
|
||||||
AttachedRigidbody.SetVelocity(targetVelocity);
|
AttachedRigidbody.SetVelocity(targetVelocity);
|
||||||
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
||||||
|
@ -278,7 +278,7 @@ namespace QSB.Syncs
|
|||||||
return Vector3.SmoothDamp(currentPosition, targetPosition, ref _positionSmoothVelocity, SmoothTime);
|
return Vector3.SmoothDamp(currentPosition, targetPosition, ref _positionSmoothVelocity, SmoothTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReferenceTransform(Transform referenceTransform)
|
public virtual void SetReferenceTransform(Transform referenceTransform)
|
||||||
{
|
{
|
||||||
if (ReferenceTransform == referenceTransform)
|
if (ReferenceTransform == referenceTransform)
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,7 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
|||||||
private Vector3 _prevAngularVelocity;
|
private Vector3 _prevAngularVelocity;
|
||||||
|
|
||||||
protected OWRigidbody AttachedRigidbody { get; private set; }
|
protected OWRigidbody AttachedRigidbody { get; private set; }
|
||||||
|
public OWRigidbody ReferenceRigidbody { get; private set; }
|
||||||
|
|
||||||
protected abstract OWRigidbody InitAttachedRigidbody();
|
protected abstract OWRigidbody InitAttachedRigidbody();
|
||||||
|
|
||||||
@ -26,6 +27,17 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
|||||||
return AttachedRigidbody ? AttachedRigidbody.transform : null;
|
return AttachedRigidbody ? AttachedRigidbody.transform : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void SetReferenceTransform(Transform referenceTransform)
|
||||||
|
{
|
||||||
|
if (ReferenceTransform == referenceTransform)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.SetReferenceTransform(referenceTransform);
|
||||||
|
ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void UpdatePrevData()
|
protected override void UpdatePrevData()
|
||||||
{
|
{
|
||||||
base.UpdatePrevData();
|
base.UpdatePrevData();
|
||||||
@ -51,8 +63,8 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
|||||||
{
|
{
|
||||||
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
|
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
|
||||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
|
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
|
||||||
_relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
|
_relativeVelocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
|
||||||
_relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
|
_relativeAngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ApplyToAttached()
|
protected override void ApplyToAttached()
|
||||||
@ -72,8 +84,8 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
|||||||
AttachedRigidbody.MoveToPosition(positionToSet);
|
AttachedRigidbody.MoveToPosition(positionToSet);
|
||||||
AttachedRigidbody.MoveToRotation(rotationToSet);
|
AttachedRigidbody.MoveToRotation(rotationToSet);
|
||||||
|
|
||||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
|
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
|
||||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
|
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
|
||||||
|
|
||||||
AttachedRigidbody.SetVelocity(targetVelocity);
|
AttachedRigidbody.SetVelocity(targetVelocity);
|
||||||
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
||||||
|
Loading…
Reference in New Issue
Block a user