Build rope from code
This commit is contained in:
parent
c0d9c685ca
commit
ae60d7b1b4
|
@ -72,6 +72,7 @@ public class RopeSimulator : MonoBehaviour
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
// Example of using rope builder
|
||||||
//rope = new RopeBuilder()
|
//rope = new RopeBuilder()
|
||||||
// .AddPoint(new Point(testPos, locked: true))
|
// .AddPoint(new Point(testPos, locked: true))
|
||||||
// .AddPoint(new Point(testPos.Add(x:5f)))
|
// .AddPoint(new Point(testPos.Add(x:5f)))
|
||||||
|
@ -83,13 +84,36 @@ public class RopeSimulator : MonoBehaviour
|
||||||
// .ConnectPoints(2, 3)
|
// .ConnectPoints(2, 3)
|
||||||
// .ConnectPoints(3, 4)
|
// .ConnectPoints(3, 4)
|
||||||
// .Build();
|
// .Build();
|
||||||
|
|
||||||
|
// Build rope if rope joints specified in inspector
|
||||||
|
if (start != null && end != null)
|
||||||
|
BuildRope(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BuildRope(RopeJoint start, RopeJoint end)
|
||||||
|
{
|
||||||
|
// Sanity check if rope simulator was initialized before
|
||||||
|
if (this.start != null)
|
||||||
|
{
|
||||||
|
start.playerInput.ropeLengthExtend -= ExtendRope;
|
||||||
|
start.playerInput.ropeLengthShrinken -= ShrinkenRope;
|
||||||
|
}
|
||||||
|
if (this.end != null)
|
||||||
|
{
|
||||||
|
end.playerInput.ropeLengthExtend -= ExtendRope;
|
||||||
|
end.playerInput.ropeLengthShrinken -= ShrinkenRope;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
|
||||||
Rebuild();
|
Rebuild();
|
||||||
|
|
||||||
start.playerInput.ropeLengthShrinken += ShrinkenRope;
|
this.start.playerInput.ropeLengthShrinken += ShrinkenRope;
|
||||||
end.playerInput.ropeLengthShrinken += ShrinkenRope;
|
this.end.playerInput.ropeLengthShrinken += ShrinkenRope;
|
||||||
|
|
||||||
start.playerInput.ropeLengthExtend += ExtendRope;
|
this.start.playerInput.ropeLengthExtend += ExtendRope;
|
||||||
end.playerInput.ropeLengthExtend += ExtendRope;
|
this.end.playerInput.ropeLengthExtend += ExtendRope;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShrinkenRope(int playerNumber)
|
void ShrinkenRope(int playerNumber)
|
||||||
|
@ -215,6 +239,10 @@ public class RopeSimulator : MonoBehaviour
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
// Dont update if no rope is initialized
|
||||||
|
if (start == null || end == null)
|
||||||
|
return;
|
||||||
|
|
||||||
//Debug.Log($"overshoot: {rope.CalculateLengthOvershoot()}");
|
//Debug.Log($"overshoot: {rope.CalculateLengthOvershoot()}");
|
||||||
//ShrinkenRope(1);
|
//ShrinkenRope(1);
|
||||||
//ExtendRope(0);
|
//ExtendRope(0);
|
||||||
|
|
Loading…
Reference in New Issue