I’m a noob when it comes to unity and I’m trying to program limb drag. (basically dynamic bone or jiggle, but simpler)
However it’s more or less not working at all (bone stays at a weird angle and doesn’t move), and there’s probably something blatantly wrong with the concept. Any idea what I’m doing wrong (or horribly misunderstanding.)
public class limb_drag : MonoBehaviour
{
Vector3 prev_child_position;
Vector3 target_position;
Quaternion delay_rot;
Quaternion prev_rotation;
public float delay_amount;
public Transform child;
// Start is called before the first frame update
void Start()
{
child = transform.GetChild(0);
prev_child_position = child.transform.position;
delay_rot = Quaternion.identity;
prev_rotation = transform.rotation;
}
// Update is called once per frame
void Update()
{
//undo delay from last step
transform.rotation = transform.rotation * Quaternion.Inverse(delay_rot);
///save position of the end of this bone
prev_child_position = child.transform.position;
///save current rotation of bone
prev_rotation = transform.rotation;
///look at the saved position of the child bone from the last step
transform.LookAt(prev_child_position);
//lerp between the orriginal rotation and the look rotation by 0.1 or so
delay_rot = Quaternion.Lerp(prev_rotation, transform.rotation, delay_amount);
///set rotation back to before look
transform.rotation = prev_rotation;
///rotate using lerped value
transform.rotation = transform.rotation * delay_rot;
}
}