{"id":430,"date":"2019-10-09T21:11:24","date_gmt":"2019-10-09T13:11:24","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=430"},"modified":"2021-01-19T18:40:47","modified_gmt":"2021-01-19T10:40:47","slug":"vector3-lerp%e5%92%8cvector3-slerp","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=430","title":{"rendered":"[Unity]Vector3.lerp\u548cVector3.Slerp"},"content":{"rendered":"\n<p>\u5bf9\u4e8e\u65b9\u5411\u5411\u91cf\uff0c\u4f7f\u7528Vector3.lerp\u662f\u4e0d\u884c\u7684\uff0c\u6bd4\u5982\u5bf9\u4e00\u4e2adir\u548c-dir\u8fdb\u884c\u63d2\u503c\uff0c\u662f\u65e0\u6548\u7684\uff1b\u6b63\u786e\u7684\u65b9\u5f0f\u662f\u4f7f\u7528Vector3.Slerp<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class LerpTestProj : MonoBehaviour\n{\n    const int section = 50;\n    void OnDrawGizmos()\n    {\n        DrawSample(Vector3.forward, Vector3.left, 1.0f, 0.0f);\n        DrawSample(Vector3.forward, Vector3.back, 1.0f, -3.0f);\n    }\n\n    private static void DrawSample(Vector3 dir0, Vector3 dir1, float x, float z)\n    {\n        Vector3 p0 = new Vector3(-x, 0, z);\n        Gizmos.color = Color.red;\n        Gizmos.DrawSphere(p0, 0.1f);\n        for (int i = 0; i &lt;= section; ++i)\n        {\n            float t = i \/ (float)section;\n            Vector3 dir = Vector3.Lerp(dir0, dir1, t);\n            Gizmos.DrawLine(p0, p0 + dir);\n        }\n\n        Vector3 p1 = new Vector3(x, 0, z);\n        Gizmos.color = Color.green;\n        Gizmos.DrawSphere(p1, 0.1f);\n        for (int i = 0; i &lt;= section; ++i)\n        {\n            float t = i \/ (float)section;\n            Vector3 dir = Vector3.Slerp(dir0, dir1, t);\n            Gizmos.DrawLine(p1, p1 + dir);\n        }\n    }\n}\n\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"756\" height=\"740\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/10\/image.png\" alt=\"\" class=\"wp-image-431\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/10\/image.png 756w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/10\/image-300x294.png 300w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/10\/image-660x646.png 660w\" sizes=\"(max-width: 756px) 100vw, 756px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8e\u65b9\u5411\u5411\u91cf\uff0c\u4f7f\u7528Vector3.lerp\u662f\u4e0d\u884c\u7684\uff0c\u6bd4\u5982\u5bf9\u4e00\u4e2adir\u548c-dir\u8fdb\u884c\u63d2\u503c\uff0c\u662f\u65e0\u6548\u7684\uff1b\u6b63\u786e\u7684\u65b9\u5f0f\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[18],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/430"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=430"}],"version-history":[{"count":4,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/430\/revisions"}],"predecessor-version":[{"id":572,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/430\/revisions\/572"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}