I have a board consisting of a three bone armature. Both noses of the board send out a raycast to the terrain below it. The front nose of the board Board-Front brings back the RaycastHit frontHit and the back nose of the board Board-Back brings back the RaycastHit backHit. What I want to happen is: the middle bone Board-Root rotates to the same exact slope as the slope between frontHit and backHit, or the example result in Screen 2. I’ve tried numerous ways to achieve this result, but screen 1 is really where I’ve progressed. I deleted past attempts at rotating the board as such in the code below and have just given you what is currently there.
public class ChangeBoardAngle : MonoBehaviour {
RaycastHit frontHit;
RaycastHit backHit;
// Update is called once per frame
void Update ()
{
if (Physics.Raycast(transform.Find("Armature/Board_Root/Board_Front").position, transform.up * -1, out frontHit, 0.1f))
{
if (Physics.Raycast(transform.Find("Armature/Board_Root/Board_Back").position, transform.up * -1, out backHit, 0.1f))
{
Debug.DrawLine(transform.Find("Armature/Board_Root/Board_Front").position, frontHit.point, Color.green);
Debug.DrawLine(transform.Find("Armature/Board_Root/Board_Back").position, backHit.point, Color.green);
}
}
}
}