<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Topdown游戲中Input朝向的轉化

      前提

      在Topdown雙搖桿游戲中,我們需要將搖桿輸入朝向轉到攝像機空間,以實現往前走是往屏幕的前方,往后是往屏幕的后方,而不是原始的輸入朝向。

      我們只討論固定視角并且player只有y軸旋轉的游戲。

      實現

      需要進行一個Vector2的映射

       1 private static Vector3 ViewSpaceToGroundSpace(float cameraAngleY, Vector2 vec)
       2 {
       3     float angleRad = -cameraAngleY * Mathf.Deg2Rad;
       4     float cos = Mathf.Cos(angleRad);
       5     float sin = Mathf.Sin(angleRad);
       6 
       7     Vector2 rotated = new Vector2(
       8         vec.x * cos - vec.y * sin,
       9         vec.x * sin + vec.y * cos
      10     );
      11 
      12     return new Vector3(rotated.x, 0f, rotated.y);
      13 }

       

      旋轉和瞄準

      雙搖桿下我們需要區分旋轉和瞄準的實現。

      其中旋轉的實現,鼠標和搖桿是一致的

       

      1       private static Vector3 GetMovementInputGroundSpace(Transform camera, int horizontalActionId, int verticalActionId, float deadZone)
      2         {
      3             var input = InputExtension.GetAxis2D(horizontalActionId, verticalActionId);
      4             if (input.sqrMagnitude > 1) input = input.normalized;
      5             input = InputExtension.InputWithRadialDeadZone(input.x, input.y, deadZone);
      6             return ViewUtils.ViewSpaceToGroundSpace(camera, input).normalized;
      7         }

       

      瞄準朝向的獲取,鼠標相對復雜一點,需要在開火的水平面做映射

       

       

       1         private static Vector3 GetAimInputInGroundSpace(GameEntity gameEntity, Camera camera, int horizontalActionId, int verticalActionId)
       2         {
       3             if (InputExtension.IsKeyboarding())
       4             {
       5                 if (InputExtension.GetButton(InputAction.Aim))
       6                 { 9                     var playerFirePoint = gameEntity.GetObject<WeaponFirePointTag>().Component;
      10                     Transform playerTransform = gameEntity.Get<Transform>();
      11                     Vector3 refPosition = playerTransform.position;
      13                     refPosition.y = playerFirePoint.position.y;
      14                     var ray = camera.ScreenPointToRay(InputExtension.MousePosition);
      15                     //we need a plane to project the aim direction to the aiming ground : https://forum.unity.com/threads/3rd-person-look-at-mouse-script.1078358/
      16                     var aimingPlane = new Plane(Vector3.up, refPosition);
      17                     aimingPlane.Raycast(ray, out float distance);
      18                     var aimDestDirection = (ray.origin + distance * ray.direction - refPosition).normalized;
      19                     var rotation = Quaternion.LookRotation(aimDestDirection);
      20                     return rotation * Vector3.forward;
      21                 }
      22 
      23                 return Vector3.zero;
      24             }
      25 
      26             var input = InputExtension.GetAxis2D(horizontalActionId, verticalActionId);
      27             return ViewUtils.ViewSpaceToGroundSpace(camera, input).normalized;
      28         }

       

      posted @ 2025-04-07 14:37  sun_dust_shadow  閱讀(25)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 临夏市| 麻豆精品一区二区三区蜜桃| 精品亚洲女同一区二区| 中文字幕午夜福利片午夜福利片97 | 国产成AV人片久青草影院| 国产一区二区三区精品综合| 欧洲亚洲精品免费二区| 久久久久久久久久久久中文字幕| 乱60一70归性欧老妇| 国产午夜精品久久一二区| 国产综合精品一区二区三区| 国产成人夜色高潮福利app| 国产成人综合久久亚洲av| 国产91特黄特色A级毛片| 四虎库影成人在线播放| 日日摸夜夜添夜夜添国产三级| 亚洲色一色噜一噜噜噜| 疯狂的欧美乱大交| 久操热在线视频免费观看| 亚洲成人av在线资源| 亚洲日韩成人av无码网站| 色吊丝一区二区中文字幕| 国产成人啪精品午夜网站| 贵溪市| 亚洲午夜亚洲精品国产成人| 欧美精品一区二区在线观看播放| 蕉岭县| 男人猛躁进女人免费播放| 亚洲影院丰满少妇中文字幕无码| 国产精品区一区第一页| AI做受???高潮AAAA视频| 丰满爆乳一区二区三区| 道真| 97精品人妻系列无码人妻| 欧美啪啪网| 国产综合久久99久久| 激情综合网五月婷婷| AV老司机AV天堂| 天堂mv在线mv免费mv香蕉| 亚洲国产一成人久久精品| 日韩av无码精品人妻系列|