mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-23 06:40:56 +00:00
fix playerheadrotationsync giving errors
This commit is contained in:
parent
64280dcc4c
commit
c8dd5a8dfa
@ -27,18 +27,17 @@ namespace QSB.Animation.Player
|
||||
}
|
||||
if (to == null || from == null)
|
||||
{
|
||||
// Doing the return this way so you can see if one or both are null
|
||||
return;
|
||||
}
|
||||
_from = from;
|
||||
_to = to;
|
||||
if (_from.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - \"From\" ({from.name}) controller is null.", MessageType.Warning);
|
||||
_from.runtimeAnimatorController = _to.runtimeAnimatorController;
|
||||
}
|
||||
else if (_to.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - \"To\" ({to.name}) controller is null.", MessageType.Warning);
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
|
@ -12,7 +12,6 @@ namespace QSB.Animation.Player
|
||||
|
||||
public void Init(Transform lookBase)
|
||||
{
|
||||
DebugLog.DebugWrite($"Init - attached to {gameObject.name}");
|
||||
_attachedAnimator = GetComponent<Animator>();
|
||||
_lookBase = lookBase;
|
||||
_isSetUp = true;
|
||||
|
@ -35,6 +35,7 @@ namespace QSB.Syncs.TransformSync
|
||||
private float _previousDistance;
|
||||
private Vector3 _positionSmoothVelocity;
|
||||
private Quaternion _rotationSmoothVelocity;
|
||||
private string _logName => $"{PlayerId}.{GetType().Name}";
|
||||
protected IntermediaryTransform _intermediaryTransform;
|
||||
|
||||
public virtual void Start()
|
||||
@ -57,11 +58,15 @@ namespace QSB.Syncs.TransformSync
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse) =>
|
||||
_isInitialized = false;
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
=> _isInitialized = false;
|
||||
|
||||
protected virtual void Init()
|
||||
{
|
||||
if (!QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {_logName} is being init-ed when not in the universe!", MessageType.Error);
|
||||
}
|
||||
if (!HasAuthority && AttachedObject != null)
|
||||
{
|
||||
Destroy(AttachedObject);
|
||||
@ -112,7 +117,7 @@ namespace QSB.Syncs.TransformSync
|
||||
|
||||
if (_intermediaryTransform.GetPosition() == Vector3.zero)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - {PlayerId}.{GetType().Name} at (0,0,0)! - Given position was {pos}", MessageType.Warning);
|
||||
DebugLog.ToConsole($"Warning - {_logName} at (0,0,0)! - Given position was {pos}", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +140,12 @@ namespace QSB.Syncs.TransformSync
|
||||
|
||||
if (AttachedObject == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - AttachedObject {Player.PlayerId}.{GetType().Name} is null.", MessageType.Warning);
|
||||
DebugLog.ToConsole($"Warning - AttachedObject {_logName} is null.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AttachedObject.activeInHierarchy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@ -186,7 +196,7 @@ namespace QSB.Syncs.TransformSync
|
||||
_intermediaryTransform.SetReferenceTransform(transform);
|
||||
if (AttachedObject == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - AttachedObject was null for {PlayerId}.{GetType().Name} when trying to set reference transform to {transform.name}. Waiting until not null...", MessageType.Warning);
|
||||
DebugLog.ToConsole($"Warning - AttachedObject was null for {_logName} when trying to set reference transform to {transform.name}. Waiting until not null...", MessageType.Warning);
|
||||
QSBCore.UnityEvents.RunWhen(
|
||||
() => AttachedObject != null,
|
||||
() => ReparentAttachedObject(transform));
|
||||
|
@ -1,4 +1,5 @@
|
||||
using QSB.Utility;
|
||||
using OWML.Common;
|
||||
using QSB.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.TransformSync
|
||||
@ -50,7 +51,7 @@ namespace QSB.Syncs.TransformSync
|
||||
{
|
||||
if (_referenceTransform == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Error - _referenceTransform has not been set for {_attachedTransform.name}", OWML.Common.MessageType.Error);
|
||||
DebugLog.DebugWrite($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -65,7 +66,7 @@ namespace QSB.Syncs.TransformSync
|
||||
{
|
||||
if (_referenceTransform == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Error - _referenceTransform has not been set for {_attachedTransform.name}", OWML.Common.MessageType.Error);
|
||||
DebugLog.DebugWrite($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
SetRotation(_referenceTransform.InverseTransformRotation(worldRotation));
|
||||
@ -87,12 +88,26 @@ namespace QSB.Syncs.TransformSync
|
||||
/// Returns the world position the VISIBLE transform should be set to, from the INVISIBLE transform.
|
||||
/// </summary>
|
||||
public Vector3 GetTargetPosition_Unparented()
|
||||
=> _referenceTransform.TransformPoint(GetPosition());
|
||||
{
|
||||
if (_referenceTransform == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error);
|
||||
return Vector3.zero;
|
||||
}
|
||||
return _referenceTransform.TransformPoint(GetPosition());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the world rotation the VISIBLE transform should be set to, from the INVISIBLE transform.
|
||||
/// </summary>
|
||||
public Quaternion GetTargetRotation_Unparented()
|
||||
=> _referenceTransform.TransformRotation(GetRotation());
|
||||
{
|
||||
if (_referenceTransform == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Error - _referenceTransform has not been set for {_attachedTransform.name}", MessageType.Error);
|
||||
return Quaternion.identity;
|
||||
}
|
||||
return _referenceTransform.TransformRotation(GetRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.SectorSync;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET.Transport;
|
||||
using System.Collections.Generic;
|
||||
@ -36,10 +37,6 @@ namespace QSB.Syncs.TransformSync
|
||||
{
|
||||
SetReferenceTransform(closestSector.Transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
_isInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer)
|
||||
@ -82,6 +79,24 @@ namespace QSB.Syncs.TransformSync
|
||||
base.DeserializeTransform(reader);
|
||||
}
|
||||
|
||||
protected override void UpdateTransform()
|
||||
{
|
||||
if ((ReferenceTransform == null || ReferenceSector == null) && QSBSectorManager.Instance.IsReady)
|
||||
{
|
||||
var closestSector = SectorSync.GetClosestSector(AttachedObject.transform);
|
||||
if (closestSector != null)
|
||||
{
|
||||
SetReferenceTransform(closestSector.Transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
base.UpdateTransform();
|
||||
}
|
||||
|
||||
public void SetReferenceSector(QSBSector sector)
|
||||
{
|
||||
ReferenceSector = sector;
|
||||
|
@ -91,7 +91,6 @@ namespace QSB.WorldSync
|
||||
DebugLog.ToConsole($"Error - Exception in OnRemoval() for {item.GetType()}. Message : {e.InnerException.Message}, Stack trace : {e.InnerException.StackTrace}", MessageType.Error);
|
||||
}
|
||||
}
|
||||
DebugLog.DebugWrite($"Removing {typeof(TWorldObject).Name} : {WorldObjects.Count(x => x is TWorldObject)} instances.");
|
||||
WorldObjects.RemoveAll(x => x is TWorldObject);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user