I have a script for making my character turn, and I have a script which rotates it based on the leg positions (for making my spider wobble and align to the terrain). Do any of you know how I can make these work together?
Currently #1 makes #2 not able to turn anymore.
#1:
private void Update()
{
lastBodyUp = transform.up;
nbLegs = legTarget.Length;
if (nbLegs > 3 && bodyOrientation)
{
Vector3 v1 = legTarget[0].position - legTarget[3].position;
Vector3 v2 = legTarget[2].position - legTarget[1].position;
Vector3 normal = Vector3.Cross(v1, v2).normalized;
Vector3 up = Vector3.Lerp(lastBodyUp, normal, 1f / (float)(smoothness + 1));
// This works, but interfers with the mouseLook rotation of the Character
transform.up = up; // <==
lastBodyUp = up;
}
}
In this #1 code I do the mean position of my 4 legs, and rotates it based on their positions. It looks great for mechs and spiders on its own.
#2:
var step = RotationSpeed * Time.deltaTime;
Quaternion lookRotation = Quaternion.Euler(0f, Camera.main.transform.eulerAngles.y, 0f);
transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, step);
In this code I’ve used Cinemachine, and use the main camera to determine the direction of the camera, then make the character turn slowly towards it (steering with your camera)
I’ll also add that these are two different files on the same gameobjects.
I’ve also tried to play around with adding physics rotations instead, but with no luck yet.
The ideal solution is some way of adding these transforms together, to make both of them work somehow