23-06-2023, 06:00 PM
(This post was last modified: 23-06-2023, 06:36 PM by swancollective.)
Thank you so much for the quick reply and your code - it seems to work! BUT! Only thing, since adding the script, Unity editor keeps crashing on me, also it crashed during build. After that the build succeeded, but the app crashed on my phone. I troubleshot it multiple times and this behavior only happens when this script is present. Maybe any clue why this could be?
As to your question, this is GPT-4s best attempt of resetting the softbody (which also didn't work, after hours of iterating):
As to your question, this is GPT-4s best attempt of resetting the softbody (which also didn't work, after hours of iterating):
Code:
using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiSoftbody))]
public class ResetObiSoftbody : MonoBehaviour {
ObiSoftbody softbody;
Vector4[] originalPositions;
void Awake(){
softbody = GetComponent<ObiSoftbody>();
originalPositions = new Vector4[softbody.solverIndices.Length];
// Store the original positions
for (int i = 0; i < softbody.solverIndices.Length; ++i){
int solverIndex = softbody.solverIndices[i];
originalPositions[i] = softbody.solver.positions[solverIndex];
}
}
public void ResetToOriginalPosition(){
// Reset the positions
for (int i = 0; i < softbody.solverIndices.Length; ++i){
int solverIndex = softbody.solverIndices[i];
softbody.solver.positions[solverIndex] = originalPositions[i];
}
}
}