Spaces:
Runtime error
Runtime error
using System; | |
using Photon.Deterministic; | |
namespace Quantum | |
{ | |
unsafe partial struct ChainItem | |
{ | |
public void Update(FrameThreadSafe frame, ref ChainItemSystem.Filter filter) | |
{ | |
// READ-ONLY for this component, PLEASE | |
if (frame.TryGetPointer<Chain>(Chain, out var chain)) | |
{ | |
if (chain->Count <= Index) | |
{ | |
Destroy = true; | |
return; | |
} | |
int indexFrom = (chain->Current - Index + chain->Positions.Length - 2) % chain->Positions.Length; | |
int indexTo = (indexFrom + 1) % chain->Positions.Length; | |
FPVector3 from = chain->Positions[indexFrom]; | |
FPVector3 to = chain->Positions[indexTo]; | |
FPVector3 position = FPVector3.Lerp(from, to, chain->Alpha); | |
filter.Transform->Position = position; | |
FPVector3 direction = (to - from).Normalized; | |
FPQuaternion desiredRotation = FPQuaternion.LookRotation(direction); | |
FP angle = FPQuaternion.Angle(desiredRotation, filter.Transform->Rotation); | |
if (angle < SnapAngle) | |
{ | |
filter.Transform->Rotation = FPQuaternion.RotateTowards(filter.Transform->Rotation, desiredRotation, RotationSpeed * frame.DeltaTime); | |
} | |
else | |
{ | |
filter.Transform->Rotation = desiredRotation; | |
} | |
} | |
} | |
} | |
} | |