I have a ConfigurableJoint body that points at an object but I want to use its orientation then make it point towards all other dinos. here’s the code:
private void Update()
{
TurnTowards();
if (isWalking)
{
leftLeg.UpdateLeg(-walkcycle);
rightLeg.UpdateLeg(walkcycle);
walkcycle += walkSpeed * Time.deltaTime;
}
else
{
rightLeg.UpdateLegStationary();
leftLeg.UpdateLegStationary();
}
Boid(dinos);
}
private void Boid(string dinos)
{
Quaternion startDir = body.targetRotation;
Quaternion target = startDir;
foreach (GameObject dino in GameObject.FindGameObjectsWithTag(dinos))
{
if (!dino.transform.IsChildOf(transform) && Vector3.Distance(dino.transform.position, body.transform.position) < maxHerdDist)
{
Vector3 direction = dino.transform.position - body.transform.position;
direction = Vector3.ProjectOnPlane(direction, Vector3.up);
target *= Quaternion.LookRotation(direction);
//target.y += Quaternion.Inverse(Quaternion.LookRotation(direction)).y / join * Vector3.Distance(dino.transform.position, body.transform.position);
}
}
body.targetRotation = target;
}
void TurnTowards()
{
Vector3 direction = player.position - body.transform.position;
direction = Vector3.ProjectOnPlane(direction, Vector3.up);
body.targetRotation = Quaternion.Inverse(Quaternion.LookRotation(direction));
}
The problem with the result is the joint is constantly spinning in circles.