So i have creatures roaming over a plain with hills. I am using Quaternion.lookRotation to orient their facing direction, and hit.normal is giving me the normals of the plain so the creatures are oriented to the ground. This only seems to be working on one axis at any time. The creatures will either pitch forward, or sidewise, but will not do both at the same time.
you can wander around the hills too if you’d like: http://aylogames.com/wolfireStuff/glidingTestWithFlapping/glidingTestWithFlapping.html
Any clues?
RaycastHit hit;
Physics.Raycast(transform.position, Vector3.down, out hit);
Debug.DrawRay(transform.position, Vector3.up, Color.blue, 2);
if (Physics.Raycast(transform.position, Vector3.down, 2)) {
storeNormal = hit.normal;
//Debug.Log("Normal hit: " + storeNormal);
Debug.DrawRay(transform.position, storeNormal, Color.green, 2);
}
//Apply changes to each child of the game object
foreach (Transform child in transform) {
if (moveDirection.sqrMagnitude > 0) {
//myAnimation.SetBool("Run", true); //Changes avatar to running state
var targetRotation = Quaternion.LookRotation(moveDirection, storeNormal); //set target towards direction of motion
child.rotation = child.rotation.EaseTowards(targetRotation, turnSpeed); //rotate towards the direction of motion
myRotation = child.rotation;