Files
aibis-dream/Assets/Scripts/FixSystem/Line/VerletStick.cs
T
2025-01-25 13:29:46 +08:00

36 lines
980 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VerletStick
{
private VerletParticle particleA;
private VerletParticle particleB;
private float length;
public float stiffness = 0.3f; // Add this line
public VerletStick(VerletParticle particleA, VerletParticle particleB, float length)
{
this.particleA = particleA;
this.particleB = particleB;
this.length = length;
}
public void UpdateStick()
{
float currentLength = Vector3.Distance(particleA.position, particleB.position);
float difference = length - currentLength;
Vector3 direction = (particleB.position - particleA.position).normalized;
if (!particleA.isLocked)
{
particleA.position -= direction * difference * stiffness;
}
if (!particleB.isLocked)
{
particleB.position += direction * difference * stiffness;
}
}
}