funny moments with kinematic simulation and alignment

This commit is contained in:
JohnCorby 2021-12-01 03:55:56 -08:00
parent aa28364c55
commit 7b81e1b4e0
4 changed files with 68 additions and 8 deletions

View File

@ -67,8 +67,6 @@ namespace QSB.Anglerfish.TransformSync
protected override void OnRenderObject()
{
base.OnRenderObject();
if (!QSBCore.WorldObjectsReady
|| !QSBCore.ShowLinesInDebug
|| !IsReady
@ -78,6 +76,8 @@ namespace QSB.Anglerfish.TransformSync
return;
}
base.OnRenderObject();
Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._arrivalDistance, Color.blue);
Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._pursueDistance, Color.red);
Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._escapeDistance, Color.yellow);

View File

@ -1,6 +1,8 @@
using System.Collections.Generic;
using QSB.JellyfishSync.WorldObjects;
using QSB.Syncs;
using QSB.Syncs.Unsectored.Rigidbodies;
using QSB.Utility;
using QSB.WorldSync;
using QuantumUNET.Transport;
using UnityEngine;
@ -49,11 +51,14 @@ namespace QSB.JellyfishSync.TransformSync
_shouldUpdate = true;
}
/// replacement using SetPosition/Rotation instead of Move
protected override bool UpdateTransform()
{
if (HasAuthority)
{
return base.UpdateTransform();
_qsbJellyfish.Align = true;
SetValuesToSync();
return true;
}
if (!_shouldUpdate)
@ -62,14 +67,60 @@ namespace QSB.JellyfishSync.TransformSync
}
_shouldUpdate = false;
return base.UpdateTransform();
var targetPos = ReferenceTransform.DecodePos(transform.position);
var targetRot = ReferenceTransform.DecodeRot(transform.rotation);
if (targetPos == Vector3.zero || transform.position == Vector3.zero)
{
return false;
}
var positionToSet = targetPos;
var rotationToSet = targetRot;
if (UseInterpolation)
{
positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos);
rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
}
var hasMoved = CustomHasMoved(
transform.position,
_localPrevPosition,
transform.rotation,
_localPrevRotation,
_relativeVelocity,
_localPrevVelocity,
_relativeAngularVelocity,
_localPrevAngularVelocity);
_localPrevPosition = transform.position;
_localPrevRotation = transform.rotation;
_localPrevVelocity = _relativeVelocity;
_localPrevAngularVelocity = _relativeAngularVelocity;
if (!hasMoved)
{
return true;
}
_qsbJellyfish.Align = false;
((OWRigidbody)AttachedObject).SetPosition(positionToSet);
((OWRigidbody)AttachedObject).SetRotation(rotationToSet);
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos);
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity);
((OWRigidbody)AttachedObject).SetVelocity(targetVelocity);
((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity);
return true;
}
protected override void OnRenderObject()
{
base.OnRenderObject();
if (!QSBCore.WorldObjectsReady
|| !QSBCore.ShowLinesInDebug
|| !IsReady
@ -79,10 +130,12 @@ namespace QSB.JellyfishSync.TransformSync
return;
}
base.OnRenderObject();
var jellyfish = _qsbJellyfish.AttachedObject;
var position = ReferenceTransform.position;
var dir = Vector3.Normalize(jellyfish.transform.position - position);
Popcron.Gizmos.Line(position + dir * jellyfish._lowerLimit, position + dir * jellyfish._upperLimit, Color.magenta);
// Popcron.Gizmos.Line(position + dir * jellyfish._lowerLimit, position + dir * jellyfish._upperLimit, Color.magenta);
Popcron.Gizmos.Sphere(position + dir * jellyfish._lowerLimit, 10f, Color.magenta);
Popcron.Gizmos.Sphere(position + dir * jellyfish._upperLimit, 10f, Color.magenta);
}

View File

@ -10,11 +10,13 @@ namespace QSB.JellyfishSync.WorldObjects
public class QSBJellyfish : WorldObject<JellyfishController>
{
public JellyfishTransformSync TransformSync;
private AlignWithTargetBody _alignWithTargetBody;
public override void Init(JellyfishController attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
_alignWithTargetBody = AttachedObject.GetRequiredComponent<AlignWithTargetBody>();
if (QSBCore.IsHost)
{
@ -47,5 +49,10 @@ namespace QSB.JellyfishSync.WorldObjects
AttachedObject._attractiveFluidVolume.SetVolumeActivation(!value);
}
}
public bool Align
{
set => _alignWithTargetBody.enabled = value;
}
}
}

View File

@ -162,7 +162,7 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
_prevAngularVelocity);
// OPTIMIZE : optimize by using sqrMagnitude
private bool CustomHasMoved(
internal bool CustomHasMoved(
Vector3 newPosition,
Vector3 prevPosition,
Quaternion newRotation,