81 lines
3.4 KiB
C#
81 lines
3.4 KiB
C#
using UnityEngine;
|
|
|
|
namespace Passer.CreatureControl {
|
|
|
|
// An insect target rig....
|
|
public class TargetRig : MonoBehaviour {
|
|
public TargetLeg leftFrontLeg;
|
|
public TargetLeg leftMiddleLeg;
|
|
public TargetLeg leftBackLeg;
|
|
|
|
public TargetLeg rightFrontLeg;
|
|
public TargetLeg rightMiddleLeg;
|
|
public TargetLeg rightBackLeg;
|
|
|
|
public Animator animator;
|
|
|
|
public void PoseLimbs() {
|
|
leftBackLeg.PoseLimb();
|
|
leftMiddleLeg.PoseLimb();
|
|
leftFrontLeg.PoseLimb();
|
|
rightBackLeg.PoseLimb();
|
|
rightMiddleLeg.PoseLimb();
|
|
rightFrontLeg.PoseLimb();
|
|
}
|
|
|
|
public void MatchTo(Insect insect) {
|
|
if (insect == null)
|
|
return;
|
|
|
|
if (leftFrontLeg != null && insect.leftFrontLeg != null)
|
|
leftFrontLeg.MatchToCreature(insect.leftFrontLeg);
|
|
if (leftMiddleLeg != null && insect.leftMiddleLeg != null)
|
|
leftMiddleLeg.MatchToCreature(insect.leftMiddleLeg);
|
|
if (leftBackLeg != null && insect.leftHindLeg != null)
|
|
leftBackLeg.MatchToCreature(insect.leftHindLeg);
|
|
|
|
if (rightFrontLeg != null && insect.rightFrontLeg != null)
|
|
rightFrontLeg.MatchToCreature(insect.rightFrontLeg);
|
|
if (rightMiddleLeg != null && insect.rightMiddleLeg != null)
|
|
rightMiddleLeg.MatchToCreature(insect.rightMiddleLeg);
|
|
if (rightBackLeg != null && insect.rightHindLeg != null)
|
|
rightBackLeg.MatchToCreature(insect.rightHindLeg);
|
|
}
|
|
|
|
public static void MoveTargetToBone(Transform target, Transform bone) {
|
|
if (target == null || bone == null)
|
|
return;
|
|
|
|
target.position = bone.position;
|
|
}
|
|
|
|
public static Quaternion TargetToBoneRotation(Transform bone, Transform nextBone) {
|
|
if (bone == null || nextBone == null)
|
|
return Quaternion.identity;
|
|
|
|
Vector3 direction = nextBone.position - bone.position;
|
|
Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up);
|
|
Quaternion toBoneRotation = Quaternion.Inverse(targetRotation) * bone.rotation;
|
|
return toBoneRotation;
|
|
}
|
|
|
|
public static Quaternion TargetToBoneRotation(Transform target, Transform nextTarget, Transform bone) {
|
|
Vector3 direction = nextTarget.position - bone.position;
|
|
Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up);
|
|
Quaternion toBoneRotation = Quaternion.Inverse(targetRotation) * bone.rotation;
|
|
return toBoneRotation;
|
|
}
|
|
|
|
public static Quaternion TargetToBoneRotation_Debug(Transform target, Transform nextTarget, Transform bone) {
|
|
Vector3 direction = nextTarget.position - target.position;
|
|
Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up);
|
|
Debug.DrawRay(bone.position, targetRotation * Vector3.forward, Color.blue);
|
|
Debug.DrawRay(bone.position, targetRotation * Vector3.up, Color.green);
|
|
|
|
Quaternion toBoneRotation = Quaternion.Inverse(targetRotation) * bone.rotation;
|
|
Debug.Log($"{targetRotation.eulerAngles} {bone.rotation.eulerAngles} -> {toBoneRotation.eulerAngles}");
|
|
return toBoneRotation;
|
|
}
|
|
}
|
|
|
|
} |