Beispiel #1
0
    void FixedUpdate()
    {
        if (hug)
        {
            // get new up vector
            var surfaceUp = hug.FindSurfaceNormal(collider);
            Debug.DrawRay(body.transform.position, surfaceUp * 100, Color.white);

            // change up vector
            Quaternion targetRotation = Quaternion.FromToRotation(body.transform.up, surfaceUp) * body.rotation;
            //body.rotation = Quaternion.Slerp(body.rotation, targetRotation, interpolationRate * Time.fixedDeltaTime);
            body.rotation = targetRotation;

            // change gravity
            g = -gForce * surfaceUp;
        }

        body.AddForce(g, ForceMode.Force);
    }