30 lines
687 B
C#
30 lines
687 B
C#
using UnityEngine;
|
|
|
|
public class FishIK : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Transform tailTarget;
|
|
|
|
[SerializeField]
|
|
private Transform tailBone;
|
|
|
|
private Quaternion lastRotate;
|
|
|
|
private Vector3 tailTargetStartPos;
|
|
|
|
private Rigidbody rBody;
|
|
|
|
private void Start()
|
|
{
|
|
rBody = GetComponent<Rigidbody>();
|
|
tailTarget.position = tailBone.position;
|
|
tailTargetStartPos = tailTarget.localPosition;
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
Vector3 target = tailTargetStartPos + new Vector3(rBody.angularVelocity.y * 0.25f, (0f - rBody.angularVelocity.x) * 0.125f, -0.3f);
|
|
tailTarget.localPosition = Vector3.MoveTowards(tailTarget.localPosition, target, Time.deltaTime * 30f);
|
|
}
|
|
}
|