File size: 1,334 Bytes
ce81a16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
        }
        
      }
    }
  }
}