forked from savagecodes/SavageCSPrediction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.cs
47 lines (37 loc) · 1.26 KB
/
Utility.cs
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
43
44
45
46
47
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;
using Vector3 = UnityEngine.Vector3;
namespace SavageCodes.Networking.ClientSidePrediction
{
public class Utility
{
public static Vector3 InterpTo(Vector3 start, Vector3 end,float speed)
{
// Distance to reach
Vector3 dist = end - start;
// If distance is too small, just set the desired location
if( dist.sqrMagnitude < 0.00001f)
{
return end;
}
// Delta Move, Clamp so we do not over shoot.
Vector3 DeltaMove = dist * Mathf.Clamp(Time.deltaTime * speed, 0, 1);
return start + DeltaMove;
}
public static float InterpTo(float start, float end,float speed)
{
// Distance to reach
float dist = start - end;
// If distance is too small, just set the desired location
if( Mathf.Abs(dist) < 0.00001f)
{
return end;
}
// Delta Move, Clamp so we do not over shoot.
float DeltaMove = dist * Mathf.Clamp(Time.deltaTime * speed, 0, 1);
return start + DeltaMove;
}
}
}