fgm24/Assets/Scripts/Rope/Rope.cs

28 lines
738 B
C#

using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Rope
{
public List<Point> points { get ; private set; }
public List<Stick> sticks { get; private set; }
public Rope(List<Point> points, List<Stick> sticks)
{
this.points = points;
this.sticks = sticks;
}
public float CalculateLengthOvershoot()
{
float sum = 0f;
foreach (Stick stick in sticks)
{
Debug.DrawRay(stick.B.position, (stick.A.position - stick.B.position).normalized * stick.desiredLength);
float dist = Vector3.Distance(stick.A.position, stick.B.position);
sum += dist - stick.desiredLength;
}
return sum;
}
}