ScreenPointToRay() public method

Returns a ray going from camera through a screen point.

public ScreenPointToRay ( Vector3 position ) : Ray
position Vector3
return Ray
コード例 #1
0
        private void ClickingOnUnitsAndStructures()
        {
            m_BoxStartPos = m_MousePosition;

            var ray = m_Camera.ScreenPointToRay(m_MousePosition);

            if (Physics.Raycast(ray, out var s_Hit, Mathf.Infinity, m_StructureMask))
            {
                // Click on blueprint prefab, return to avoid error on mouse callback
                if (s_Hit.transform.TryGetComponent(out BuildComponents _))
                {
                    return;
                }

                if (s_Hit.transform.parent.parent.TryGetComponent(out IStructure structure))
                {
                    ClickOnBuilding(structure);
                }
            }

            if (!Physics.Raycast(ray, out var u_Hit, Mathf.Infinity, m_UnitMask))
            {
                return;
            }

            if (u_Hit.transform.parent.TryGetComponent(out IUnit _))
            {
                ClickOnUnit(u_Hit.transform.parent.gameObject);
            }
        }
コード例 #2
0
    // ConvertScreenToWorld //
    // Converts Vector3's from screen to world space - by raycasting from the passed camera //
    // to a plane parallel to the camera, outputs an array of 2 Vector3's                   //
    public static Vector3[] ConvertScreenToWorld( Vector3 point_a, Vector3 point_b, Vector3 position, Camera camera )
    {
        // Convert screen touches into rays from main camera
        Ray ray_a = camera.ScreenPointToRay( point_a );
        Ray ray_b = camera.ScreenPointToRay( point_b );

        // Create a plane parallel to camera, facing the screen - then rotated by the cameras y rotation
        Vector3 parallel_to_camera = RotateY( new Vector3( 0, 0, -1 ), camera.transform.rotation.y );
        Plane plane = new Plane( parallel_to_camera, position );

        // Hit distances
        float hit1;
        float hit2;

        // Hit point Vector3's
        Vector3 hit_point_a = Vector3.zero;
        Vector3 hit_point_b = Vector3.zero;

        // Shoot ray_a at plane
        if( plane.Raycast( ray_a, out hit1 ) )
        {
            // Get where ray_a collides with the plane
            hit_point_a = ray_a.GetPoint( hit1 );
        }

        // Shoot ray_b at plane
        if( plane.Raycast( ray_b, out hit2 ) )
        {
            // Get where ray_b collides with the plane
            hit_point_b = ray_b.GetPoint( hit2 );
        }

        // Return two vectors as array
        return new Vector3[ 2 ] { hit_point_a, hit_point_b };
    }
コード例 #3
0
        /// <summary>
        /// Sets the crosshairs to the specified transform.
        /// </summary>
        /// <param name="crosshairs">The transform of the crosshairs.</param>
        public override void SetCrosshairs(Transform crosshairs)
        {
            m_CrosshairsTransform = crosshairs;

            if (m_CrosshairsTransform != null)
            {
                var screenPoint = RectTransformUtility.WorldToScreenPoint(null, m_CrosshairsTransform.position);
                m_CrosshairsDeltaRotation = Quaternion.LookRotation(m_Camera.ScreenPointToRay(screenPoint).direction, m_Transform.up) * Quaternion.Inverse(m_Transform.rotation);
                m_CrosshairsLocalPosition = m_CrosshairsTransform.localPosition;
            }
        }
コード例 #4
0
ファイル: CameraExtensions.cs プロジェクト: Exosphir/exosphir
		public static Vector3 PointOfConvergence (Camera camera) {
			Ray cornerRay = camera.ScreenPointToRay(new Vector3(0, 0, 0));
			Ray centerRay = camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));

			// Calculate angles of the corner and center ray for the trig that is about to happen

			float xzCornerAngle = Vector2.Angle(new Vector2(centerRay.direction.x, centerRay.direction.z), new Vector2(cornerRay.direction.x, cornerRay.direction.z));
			float zyCornerAngle = Vector2.Angle(new Vector2(centerRay.direction.z, centerRay.direction.y), new Vector2(cornerRay.direction.z, cornerRay.direction.y));

			// Angle "i"
			float xzCenterAngle = Vector2.Angle(new Vector2(camera.transform.right.x, camera.transform.right.z), new Vector2(centerRay.direction.x, centerRay.direction.z));
			float zyCenterAngle = Vector2.Angle(new Vector2(camera.transform.right.z, camera.transform.right.y), new Vector2(centerRay.direction.z, centerRay.direction.y));

			// Angle "o"
			float xzOuterAngle = 180.0f - (xzCornerAngle + 90.0f);
			float zyOuterAngle = 180.0f - (zyCornerAngle + 90.0f);

			// Angle "v"
			float xzPointAngle = 180.0f - (xzOuterAngle + xzCenterAngle);
			float zyPointAngle = 180.0f - (zyOuterAngle + zyCenterAngle);

			// Get the distance from center point to corner point on both planes

			Vector2 halfScreen = new Vector2(Vector3.Distance(centerRay.origin, new Vector3(cornerRay.origin.x, centerRay.origin.y, cornerRay.origin.z)), Vector3.Distance(cornerRay.origin, new Vector3(cornerRay.origin.x, centerRay.origin.y, cornerRay.origin.z)));

			// Calculate the hypotenuse of the PoC calculation triangle

			float xzHypotenuse = (Mathf.Sin(xzCenterAngle * Mathf.Deg2Rad) * halfScreen.x) / Mathf.Sin(xzPointAngle * Mathf.Deg2Rad);
			float zyHypotenuse = (Mathf.Sin(zyCenterAngle * Mathf.Deg2Rad) * halfScreen.y) / Mathf.Sin(zyPointAngle * Mathf.Deg2Rad);

			// Calculate the final PoC by calculating the PoC on both planes

			Vector3 inverseCorner = -cornerRay.direction;

			Vector2 xzPoC = new Vector2(inverseCorner.x, inverseCorner.z) * xzHypotenuse;
			Vector2 zyPoC = new Vector2(inverseCorner.z, inverseCorner.y) * zyHypotenuse;  // zyPoc.x = xzPoc.y and therefore isnt used

			Vector3 pointOfConvergence = cornerRay.origin + new Vector3(xzPoC.x, zyPoC.y, xzPoC.y);

			// DEBUG

			//Debug.DrawRay(centerRay.origin, centerRay.direction, Color.yellow);

			Debug.Log ("cA " + xzCornerAngle + " o: " + xzOuterAngle + " i: " + xzCenterAngle + " v: " + xzPointAngle + " halfScreen: " + halfScreen.x + " hyp: " + xzHypotenuse);

			Debug.DrawRay(cornerRay.origin, inverseCorner * 2.0f, Color.green);
			Debug.DrawLine(cornerRay.origin, pointOfConvergence, Color.yellow);

			return pointOfConvergence;
		}
コード例 #5
0
ファイル: CameraController.cs プロジェクト: EttienneS/karthus
        private void HandleMouseInput()
        {
            // https://www.youtube.com/watch?v=rnqF6S7PfFA&t=212s (from 12:00)
            if (Input.mouseScrollDelta.y != 0)
            {
                newZoom += Input.mouseScrollDelta.y * zoomAmount;
                newZoom  = new Vector3(newZoom.x,
                                       Mathf.Clamp(newZoom.y, minZoom, maxZoom),
                                       Mathf.Clamp(newZoom.z, -maxZoom, -minZoom));
            }

            if (Input.GetMouseButtonDown(1))
            {
                var plane = new Plane(Vector3.up, Vector3.zero);
                var ray   = Camera.ScreenPointToRay(Input.mousePosition);

                if (plane.Raycast(ray, out float entry))
                {
                    dragStartPosition = ray.GetPoint(entry);
                }
            }

            if (Input.GetMouseButton(1))
            {
                var plane = new Plane(Vector3.up, Vector3.zero);
                var ray   = Camera.ScreenPointToRay(Input.mousePosition);

                if (plane.Raycast(ray, out float entry))
                {
                    dragCurrentPosition = ray.GetPoint(entry);
                    newPosition         = transform.position + dragStartPosition - dragCurrentPosition;
                }
            }

            if (Input.GetMouseButtonDown(2))
            {
                rotateStartPosition = Input.mousePosition;
            }

            if (Input.GetMouseButton(2))
            {
                rotateCurrentPosition = Input.mousePosition;

                var diff = rotateStartPosition - rotateCurrentPosition;
                rotateStartPosition = rotateCurrentPosition;

                newRotation *= Quaternion.Euler(Vector3.up * (-diff.x / 5));
            }
        }
コード例 #6
0
        void FixedUpdate()
        {
            basicController.move(new Vector2(Input.GetAxis("Vertical"), -Input.GetAxis("Horizontal")));

            Vector3 controllerDir = new Vector3(Input.GetAxis("RightVertical"), 0, Input.GetAxis("RightHorizontal"));
            Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, camera.nearClipPlane + cursorDepth);

            detectInputType(controllerDir, mousePosition);

            if (inputType == InputType.CONTROLLER)
            {
                basicController.lookAt(controllerDir);
                crosshairInstance.SetActive(false);
            }

            if (inputType == InputType.KB)
            {
                crosshairInstance.SetActive(true);
                updateCrosshairPosition(mousePosition);
                RaycastHit hit;
                Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    Vector2 crosshairDir          = new Vector2(hit.point.x - transform.position.x, hit.point.z - transform.position.z);
                    float   rotationAngleToTarget = Vector3.SignedAngle(transform.forward, new Vector3(crosshairDir.x, 0, crosshairDir.y), Vector3.up);
                    basicController.rotate(rotationAngleToTarget);
                }
            }
        }
コード例 #7
0
ファイル: Game.cs プロジェクト: GDxU/incomplete-richman
	/// <summary>
	/// Gets the position of the mouse on the water plane.
	/// </summary>

	static public Vector3 GetMouseWaterPosition (Camera cam)
	{
		// Since the water plane is always at (0, 0, 0) and points straight up, distance
		// to plane calculation has been greatly simplified.
		Ray ray = cam.ScreenPointToRay(Input.mousePosition);
		return ray.origin - ray.direction * (ray.origin.y / ray.direction.y);
	}
コード例 #8
0
        void Update()
        {
            Ray ray = _mainCamera.ScreenPointToRay(Input.mousePosition);

            RaycastHit hitObj;

            int layerMask = 1 << 8 | 1 << 10 | 1 << 9;

            if (Physics.Raycast(ray, out hitObj, Mathf.Infinity, layerMask))
            {
                _infoFrame.SetActive(true);
                PlayerInfomation.Infomation info = hitObj.transform.GetComponent <PlayerInfomation>().info;

                _name.text  = info._name;
                _Job.text   = info._job;
                _level.text = info._level;
                _tribe.text = info._tribe;

                _infoFrame.transform.position = Input.mousePosition + new Vector3(300 / 2, -300 / 2);
            }
            else
            {
                _infoFrame.SetActive(false);
            }
        }
コード例 #9
0
        private void Update()
        {
            Ray ray = _mainCamera.ScreenPointToRay(Input.mousePosition);

            RaycastHit hitObj;

            if (Physics.Raycast(ray, out hitObj, Mathf.Infinity))
            {
                if (hitObj.transform.tag.Equals("Enemy"))
                {
                    Cursor.SetCursor(_attackCur, Vector2.zero, CursorMode.ForceSoftware);

                    if (Input.GetMouseButton(0))
                    {
                        _npcCam.SetActive(false);
                        _enemyCam.SetActive(true);

                        _uIManager.InteractWithNpc(hitObj.transform.GetComponent <NpcController>());
                    }
                }
                else if (Input.GetMouseButton(0))
                {
                    Cursor.SetCursor(_clickCur, Vector2.zero, CursorMode.ForceSoftware);
                }
                else
                {
                    Cursor.SetCursor(_normalCur, Vector2.zero, CursorMode.ForceSoftware);
                }
            }
        }
コード例 #10
0
ファイル: ProjectionUtils.cs プロジェクト: nobnak/TouchScript
 /// <summary>
 /// Projects a screen point to a plane.
 /// </summary>
 /// <param name="position">Screen point.</param>
 /// <param name="camera">The camera.</param>
 /// <param name="projectionPlane">The projection plane.</param>
 /// <returns></returns>
 public static Vector3 CameraToPlaneProjection(Vector2 position, Camera camera, Plane projectionPlane)
 {
     var ray = camera.ScreenPointToRay(position);
     var relativeIntersection = 0f;
     projectionPlane.Raycast(ray, out relativeIntersection);
     return ray.origin + ray.direction*relativeIntersection;
 }
コード例 #11
0
ファイル: OnCamera.cs プロジェクト: gmfnasg/Look
    public static bool InCamera(Camera LookCamera, GameObject go, float VisionDistance)
    {
        #region 檢查是否在指定攝影範圍內
        if (LookCamera == null)
            return false;
        Collider collider = go.GetComponent<Collider>();
        if (collider == null)
            return false;
        Plane[] planes = GeometryUtility.CalculateFrustumPlanes(LookCamera);
        bool isOnCamera = GeometryUtility.TestPlanesAABB(planes, collider.bounds);
        if (!isOnCamera)
            return false;
        #endregion 檢查是否在指定攝影範圍內


        #region 檢查是否有遮蔽物
        //這是簡陋板,只能檢查無體中新點是否有被遮擋無法判定是否有任何地方有顯示
        #region 取得看到的物體
        if (LookCamera == null)
            return false;
        Vector3 screenPoint = LookCamera.WorldToScreenPoint(go.transform.position);
        Ray ray = LookCamera.ScreenPointToRay(screenPoint);
        RaycastHit hit;
        if (!Physics.Raycast(ray, out hit, VisionDistance))
            return false;
        #endregion 取得看到的物體

        //檢查看到的物件是否是自己
        bool result = hit.transform == go.transform;
        #endregion 檢查是否有遮蔽物


        return result;
    }
コード例 #12
0
    void Update()
    {
        Vector3 tmp = transform.position;

        tmp.y = 10f;

        if (Input.GetButton("Fire1"))
        {
            ani.SetBool("Attack", true);
            weapon.type = Weapon.Type.Sword;
        }
        else if (Input.GetButton("Fire2"))
        {
            bow_time += Time.deltaTime;
            if (!bow_fullback.isPlaying)
            {
                bow_fullback.Play();
            }

            RaycastHit hit;
            Vector3    mouse = Input.mousePosition;
            if (Physics.Raycast(cam.ScreenPointToRay(mouse), out hit, 10000))
            {
                click_pos   = hit.point;
                click_pos.y = transform.position.y;
                transform.LookAt(click_pos);
                line.gameObject.SetActive(true);
                line.SetPosition(0, transform.position);
                line.SetPosition(1, click_pos);

                weapon.type = Weapon.Type.Bow;
            }
        }
        ani.SetFloat("Bow_Fire", bow_time);
    }
コード例 #13
0
    public GameObject getTargetObjects(Vector3 startpoint, Camera cam)
    {
        //GameObject[] colliderobjects = new GameObject[10];
        //RaycastHit[] hits = Physics.raycastAll(startpoint, direction, distance);
        //return colliderobjects;
        GameObject firstCollidedObject = null;
        RaycastHit hit;
        Ray fireray;
        //Startpoint is in het geval van guitexture de transform.position
        //bool success = Physics.Raycast(startpoint, direction, out hit, distance); //Werkt niet echt goed
        fireray = cam.ScreenPointToRay(startpoint);
        bool success = Physics.Raycast(fireray, out hit, distance);
        if (success){
            firstCollidedObject = hit.collider.gameObject;
            if(firstCollidedObject != null)
                ;//print("There was a hit on " + firstCollidedObject.name);
            else
                ;//print("Debug further");
        }
        if (debug)
        {
            drawRay5Sec(startpoint, hit.point);
        }

        return firstCollidedObject;
    }
コード例 #14
0
 private GameObject getGameObjectCollided(Vector3 position, Camera camera)
 {
     Ray ray = camera.ScreenPointToRay(position);
     RaycastHit hit;
     Physics.Raycast(ray, out hit);
     return hit.collider ? hit.collider.gameObject : null;
 }
コード例 #15
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="camera"></param>
 /// <param name="hit"></param>
 /// <returns></returns>
 public static bool GetRaycastHitFromCache(Camera camera, out RaycastHit hit)
 {
     RaycastHit? hitRef;
     if (!HitTestContext.raycastHits.TryGetValue(camera, out hitRef))
     {
         Ray ray = camera.ScreenPointToRay(HitTestContext.screenPoint);
         if (Physics.Raycast(ray, out hit))
         {
             HitTestContext.raycastHits[camera] = hit;
             return true;
         }
         else
         {
             HitTestContext.raycastHits[camera] = null;
             return false;
         }
     }
     else if (hitRef == null)
     {
         hit = new RaycastHit();
         return false;
     }
     else
     {
         hit = (RaycastHit)hitRef;
         return true;
     }
 }
コード例 #16
0
ファイル: Utility.cs プロジェクト: Jacko161/Unity-Project-v2
 //
 // GetMousePosition
 //
 public static Vector3 GetMousePosition( Camera camera )
 {
     RaycastHit 		hit;
     Ray 			cast = camera.ScreenPointToRay( Input.mousePosition );
     Physics.Raycast( cast, out hit );
     return hit.point;
 }
コード例 #17
0
            public int GetSelectedPieces()
            {
                /*ListManager Default*/

                //var selectedPieces = new List<Pieces>();
                //for(int i = 0; i<pieceBottons.Count(); i++)
                //{



                //    if (pieceBottons[i].PushedObject() >= 0)
                //    {

                //        selectedPieces.Add(pieceBottons[i].GetPiece());
                //        if (EnabledPiecesId.IndexOf(selectedPieces[selectedPieces.Count - 1])>=0)
                //        {
                //            //Debug.Log("Puehed !!!   " + selectedPieces[selectedPieces.Count - 1]);
                //            return selectedPieces[selectedPieces.Count-1].GetPieceId();
                //           // break;
                //        }

                //    }


                //}
                //return -1;
                if (!Input.GetMouseButtonUp(0))
                {
                    return(-1);
                }
                Ray        ray = MiniMapCamera.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                Physics.queriesHitBackfaces = true;

                if (Physics.Raycast(ray, out hit))
                {
                    var pieces = hit.transform.gameObject.GetComponent <Pieces>();
                    //Debug.Log("GetSelected Piecs : "+ hit.transform.gameObject);

                    if (pieces == null)
                    {
                        return(-1);
                    }


                    int pieceId = pieces.GetPieceId();
                    if (!ManagerStore.humanPlayer.HasPiece(pieceId))
                    {
                        return(-1);
                    }

                    return(pieceId);
                }
                else
                {
                    return(-1);
                }
            }
コード例 #18
0
 public Vector3 ScreenPointToWorldPoint(Vector3 screenPoint, Plane plane,Camera camera)
 {
     RaycastHit hit;
         if (Physics.Raycast(camera.ScreenPointToRay(screenPoint), out hit)){
             return hit.point;
         }
     return  ScreenPointToWorldPointOnPlane(screenPoint, plane, camera);
 }
コード例 #19
0
        /// <summary>
        /// Using the given camera the two touches are projectes onto the given plane and the distance is calculated
        /// </summary>
        /// <returns>
        /// The current distance.
        /// </returns>
        public float GetCurrentDistance(Camera camera, Plane plane, out Vector3 center)
        {
            Ray r1 = camera.ScreenPointToRay(firstTouch.endPosition);
            Ray r2 = camera.ScreenPointToRay(secondTouch.endPosition);

            float dist1 = 0;
            float dist2 = 0;

            plane.Raycast(r1, out dist1);
            plane.Raycast(r2, out dist2);

            Vector3 p1 = r1.GetPoint(dist1);
            Vector3 p2 = r2.GetPoint(dist2);

            center = (p2 - p1) * 0.5f + p2;
            return Vector3.Distance(p1,p2);
        }
コード例 #20
0
    public static Vector3 ScreenPointToWorldPointOnPlane( Vector3 screenPoint ,   Plane plane ,   Camera camera  )
    {
        // Set up a ray corresponding to the screen position
        Ray ray = camera.ScreenPointToRay (screenPoint);

        // Find out where the ray intersects with the plane
        return PlaneRayIntersection (plane, ray);
    }
コード例 #21
0
ファイル: IT_Utility.cs プロジェクト: tetsujp84/karaketsua
 public static GameObject GetHovered2DObject(Vector2 cursorPos, Camera camera=null)
 {
     if(camera==null) camera=Camera.main;
     if(camera==null) return null;
     Ray ray = camera.ScreenPointToRay(cursorPos);
     RaycastHit2D hit2D=Physics2D.GetRayIntersection(ray);
     return hit2D.collider!=null ? hit2D.collider.gameObject : null;
 }
コード例 #22
0
ファイル: Utils.cs プロジェクト: nicolasSagon/SeriousSwag2
	public GameObject isTargetReacheable(GameObject gObject, Camera camera){
		RaycastHit hit;
		Ray landingRay = camera.ScreenPointToRay (Input.mousePosition);
		if(Physics.Raycast(landingRay,out hit,5)){
			if(hit.collider.tag == "target")
				return hit.transform.gameObject;
		}
		return null;
	}
コード例 #23
0
        /// <summary>
        /// Projects a screen point to a plane from a camera's point of view.
        /// </summary>
        /// <param name="position">Screen point.</param>
        /// <param name="camera">The camera.</param>
        /// <param name="projectionPlane">Projection plane.</param>
        /// <returns>Projected point on the plane in World coordinates.</returns>
        public static Vector3 CameraToPlaneProjection(Vector2 position, Camera camera, Plane projectionPlane)
        {
            var distance = 0f;
            var ray = camera.ScreenPointToRay(position);
            var result = projectionPlane.Raycast(ray, out distance);
            if (!result && Mathf.Approximately(distance, 0f)) return -projectionPlane.normal * projectionPlane.GetDistanceToPoint(Vector3.zero); // perpendicular to the screen

            return ray.origin + ray.direction * distance;
        }
コード例 #24
0
ファイル: Picker.cs プロジェクト: johnsietsma/eons
 public static RaycastHit Pick( Camera camera, Vector3 point )
 {
     Ray ray = camera.ScreenPointToRay( point );
     RaycastHit hit;
     if( Physics.Raycast( ray, out hit ) ) {
         return hit;
     }
     return DefaultRaycastHit;
 }
コード例 #25
0
ファイル: IT_Utility.cs プロジェクト: tetsujp84/karaketsua
 public static GameObject GetHovered3DObject(Vector2 cursorPos, Camera camera=null)
 {
     if(camera==null) camera=Camera.main;
     if(camera==null) return null;
     RaycastHit hit;
     Ray ray = camera.ScreenPointToRay(cursorPos);
     if(Physics.Raycast(ray, out hit)) return hit.collider.gameObject;
     return null;
 }
コード例 #26
0
		public static Ray ScreenPointToRay(Camera cam, Vector2 screenPos)
		{
			if (cam != null)
			{
				return cam.ScreenPointToRay(screenPos);
			}
			Vector3 origin = screenPos;
			origin.z -= 100f;
			return new Ray(origin, Vector3.forward);
		}
コード例 #27
0
        public static Vector3 ReTranslateFromCamera(Vector3 inPos, Camera sourceCamera, Camera targetCamera, float depth)
        {
            Vector3 sourceScreen = sourceCamera.WorldToScreenPoint(inPos);

            Ray sourceRay = targetCamera.ScreenPointToRay(sourceScreen);

            Vector3 position = (sourceRay.origin + sourceRay.direction * depth);

            return position;
        }
コード例 #28
0
 public static bool checkVisible(Collider collider, Camera mainCam)
 {
     Vector3 screenPos = mainCam.WorldToScreenPoint(collider.bounds.center);
     Ray ray = mainCam.ScreenPointToRay(screenPos);
     RaycastHit hit = new RaycastHit();
     if (Physics.Raycast(ray, out hit))
         return collider == hit.collider;
     else
         return false;
 }
コード例 #29
0
ファイル: gRaycast.cs プロジェクト: gcoope/HeroesAndVillains
 /// <summary>
 /// Returns name of gameobject clicked on.
 /// </summary>
 /// <returns>The gameobject name.</returns>
 public static string RaycastColliderName(Camera camera)
 {
     RaycastHit hit;
     Ray ray = camera.ScreenPointToRay (Input.mousePosition);
     if (Physics.Raycast (ray, out hit, 100f)) {
         return hit.collider.gameObject.name;
     } else {
         return "null";
     }
 }
コード例 #30
0
        // Update is called once per frame
        private void Update()
        {
            var ray = PlayerCamera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Shader.SetGlobalVector("SpherePosition", hit.point);
                Shader.SetGlobalFloat("SphereRadius", Radius);
                Shader.SetGlobalFloat("SphereHardness", Hardness);
            }
        }
コード例 #31
0
ファイル: MeshColliderHitTest.cs プロジェクト: yinlei/Fishing
 public bool ScreenToLocal(Camera camera, Vector3 screenPoint, ref Vector2 point)
 {
     Ray ray = camera.ScreenPointToRay(screenPoint);
     RaycastHit hit;
     if (collider.Raycast(ray, out hit, 100))
     {
         point = new Vector2(hit.textureCoord.x * this.width, (1 - hit.textureCoord.y) * this.height);
         return true;
     }
     else
         return false;
 }
コード例 #32
0
 //translate the position of mouse into a point on the board
 Vector3 TranslateMousePos(Vector3 mousePos)
 {
     playerCamera = gameManager.currentCamera;
     if (playerCamera.orthographic) {
         mousePos = playerCamera.ScreenToWorldPoint(mousePos);
         mousePos.y = 0.0f;
         return mousePos;
     }
     Ray mouseRay = playerCamera.ScreenPointToRay(mousePos);
     Vector3 dest = playerCamera.transform.position + (transform.position.y - playerCamera.transform.position.y) * mouseRay.direction.normalized / mouseRay.direction.normalized.y;
     return dest;
 }
コード例 #33
0
        public static T RaycastScreen <T>(this UnityEngine.Camera cam, Vector3 screenPosition, float maxDistance = float.MaxValue, int layerMask = Physics.DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
        {
            var        ray = cam.ScreenPointToRay(screenPosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, maxDistance, layerMask, queryTriggerInteraction))
            {
                return(hit.transform.GetComponent <T>());
            }

            return(default(T));
        }
コード例 #34
0
ファイル: WeaponBase.cs プロジェクト: enpel/zombiegame-source
    public virtual void Fire(Camera camera)
    {
        Ray ray = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit = new RaycastHit();

        attackSE.PlayOnShot();
        ammoCurrent --;

        if (Physics.Raycast(ray, out hit,1000.0f)){
            HitFire(hit);
        }
    }
コード例 #35
0
ファイル: Star.cs プロジェクト: gdgeek/fly
 public void setup(Transform tran, Camera cam, Plane sky)
 {
     this.transform.SetParent (tran);
     float x = Random.Range (0.0f, Screen.width);
     float y = Random.Range (0.0f, Screen.height);
     Ray ray = cam.ScreenPointToRay (new Vector3 (x, y, 0));
     float dist = 0;
     sky.Raycast (ray, out dist);
     Vector3 p = ray.GetPoint (dist);
     this.transform.position = p;
     this.gameObject.SetActive (true);
 }
コード例 #36
0
ファイル: TopDown.cs プロジェクト: kurumsaleyup/FPSGame
        /// <summary>
        /// Returns the delta yaw rotation of the character.
        /// </summary>
        /// <param name="characterHorizontalMovement">The character's horizontal movement.</param>
        /// <param name="characterForwardMovement">The character's forward movement.</param>
        /// <param name="cameraHorizontalMovement">The camera's horizontal movement.</param>
        /// <param name="cameraVerticalMovement">The camera's vertical movement.</param>
        /// <returns>The delta yaw rotation of the character.</returns>
        public override float GetDeltaYawRotation(float characterHorizontalMovement, float characterForwardMovement, float cameraHorizontalMovement, float cameraVerticalMovement)
        {
#if UNITY_EDITOR
            if (m_LookSource == null)
            {
                Debug.LogError("Error: There is no look source attached to the character. Ensure the character has a look source attached. For player characters the look source is the Camera Controller, and AI agents use the Local Look Source.");
                return(0);
            }
#endif
            if (m_LookInMoveDirection)
            {
                if (characterHorizontalMovement != 0 || characterForwardMovement != 0)
                {
                    var inputVector = Vector3.zero;
                    inputVector.Set(characterHorizontalMovement, 0, characterForwardMovement);

                    var lookRotation = Quaternion.LookRotation(m_LookSource.Transform.rotation * inputVector.normalized);
                    return(MathUtility.ClampInnerAngle(MathUtility.InverseTransformQuaternion(m_Transform.rotation, lookRotation).eulerAngles.y));
                }
            }
            else
            {
                // The character should look towards the cursor or Mouse X/Y direction.
                if (m_PlayerInput.IsCursorVisible())
                {
                    // Cast a ray from the mouse position to an invisible plane to determine the direction that the character should look.
                    float distance;
                    var   ray             = m_Camera.ScreenPointToRay(m_PlayerInput.GetMousePosition());
                    var   characterCenter = m_Transform.position + (m_CharacterLocomotion.Up * m_CharacterLocomotion.Height / 2);
                    m_HitPlane.SetNormalAndPosition(m_CharacterLocomotion.Up, characterCenter);
                    if (m_HitPlane.Raycast(ray, out distance))
                    {
                        var rotation = Quaternion.LookRotation((ray.GetPoint(distance) - characterCenter).normalized, m_CharacterLocomotion.Up);
                        return(MathUtility.ClampInnerAngle(MathUtility.InverseTransformQuaternion(m_Transform.rotation, rotation).eulerAngles.y));
                    }
                }
                else
                {
                    // If the mouse hasn't moved then get the axis to determine a look rotation. This will be used for controllers and virtual input.
                    var direction = Vector3.zero;
                    direction.x = m_PlayerInput.GetAxis(m_PlayerInput.HorizontalLookInputName);
                    direction.z = m_PlayerInput.GetAxis(m_PlayerInput.VerticalLookInputName);
                    if (direction.sqrMagnitude > 0.1f)
                    {
                        var rotation = Quaternion.LookRotation(direction.normalized, m_CharacterLocomotion.Up);
                        return(MathUtility.ClampInnerAngle(MathUtility.InverseTransformQuaternion(m_Transform.rotation, rotation).eulerAngles.y));
                    }
                }
            }

            return(0);
        }
コード例 #37
0
        // Update is called once per frame
        private void FixedUpdate()
        {
            if (cam == null)
            {
                throw new Exception("No Camera component attached to read mouse hit point!");
            }
            ray = cam.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 100f))
            {
            }

            Debug.DrawRay(ray.origin, ray.direction * 100, Color.cyan);
        }
コード例 #38
0
        private void LookAtMouse()
        {
            Ray   cameraRay   = _camera.ScreenPointToRay(Input.mousePosition);
            Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
            float rayLength;

            if (groundPlane.Raycast(cameraRay, out rayLength))
            {
                Vector3 pointToLook = cameraRay.GetPoint(rayLength);
                Debug.DrawLine(cameraRay.origin, pointToLook, Color.blue);
                _transform.LookAt(new Vector3(pointToLook.x, _transform.position.y, pointToLook.z));
            }
        }
コード例 #39
0
ファイル: Gun.cs プロジェクト: LucidNeko/WeAreAllOne
    protected GameObject GetTargetGameObject(Camera camera, Transform barrelEnd)
    {
        Vector2 center = camera.pixelRect.center;
        Ray ray = camera.ScreenPointToRay (new Vector3 (center.x, center.y));

        RaycastHit info;
        if (Physics.Raycast (ray, out info)) {
            //			Debug.Log ("hit: " + info.collider.gameObject.name);
            return info.collider.gameObject;
        } else {
            return null;
        }
    }
コード例 #40
0
ファイル: Gun.cs プロジェクト: LucidNeko/WeAreAllOne
    protected Vector3 GetBulletTrajectory(Camera camera, Transform barrelEnd)
    {
        Vector2 center = camera.pixelRect.center;
        Ray ray = camera.ScreenPointToRay (new Vector3 (center.x, center.y));

        RaycastHit info;
        if (Physics.Raycast (ray, out info)) {
            //			Debug.Log ("hit: " + info.collider.gameObject.name);
            return (info.point - barrelEnd.position).normalized;
        } else {
            return barrelEnd.forward;
        }
    }
コード例 #41
0
        public static Vector3 GetWorldPositionOnPlane(UnityEngine.Camera p_cam, Vector3 p_screenPosition, float z)
        {
            if (p_cam == null)
            {
                return(Vector3.zero);
            }

            var ray = p_cam.ScreenPointToRay(p_screenPosition);
            var xy  = new Plane(Vector3.forward, new Vector3(0, 0, z));

            xy.Raycast(ray, out var distance);
            return(ray.GetPoint(distance));
        }
コード例 #42
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100))
            {
                agent.SetDestination(hit.point);
            }
        }
    }
コード例 #43
0
ファイル: BaseHooks.cs プロジェクト: vizkidd/MMO
        public virtual bool IsClicked(UnityEngine.Camera activeCamera, Vector3 clickLocation)
        {
            Ray        ray = activeCamera.ScreenPointToRay(clickLocation);
            RaycastHit hit;

            if (collider.Raycast(ray, out hit, 100))
            {
                Debug.Log("Hit detected on object " + name + " at point " + hit.point);
                return(true);
            }

            return(false);
        }
コード例 #44
0
 /// <summary>
 /// Reproject moved positions back onto floor plane (they move in 3D space so it can feel sluggish
 /// if we take their new position and clamp it back down to plane y
 /// </summary>
 static void ReprojectOntoFloor(ref Vector3 worldPoint, Plane floor)
 {
     UnityEngine.Camera sceneCam = UnityEngine.Camera.current;
     if (sceneCam != null)
     {
         float dist;
         Ray   camray = sceneCam.ScreenPointToRay(sceneCam.WorldToScreenPoint(worldPoint));
         if (floor.Raycast(camray, out dist))
         {
             worldPoint = camray.GetPoint(dist);
         }
     }
 }
コード例 #45
0
 static public int ScreenPointToRay(IntPtr l)
 {
     try {
         UnityEngine.Camera  self = (UnityEngine.Camera)checkSelf(l);
         UnityEngine.Vector3 a1;
         checkType(l, 2, out a1);
         var ret = self.ScreenPointToRay(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #46
0
 static public int ScreenPointToRay(IntPtr l)
 {
     try{
         UnityEngine.Camera  self = (UnityEngine.Camera)checkSelf(l);
         UnityEngine.Vector3 a1;
         checkType(l, 2, out a1);
         UnityEngine.Ray ret = self.ScreenPointToRay(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #47
0
ファイル: CameraManager.cs プロジェクト: Gapti/MonsterClinic
	/// <summary>
	/// Align all transforms so they are in the screen center
	/// </summary>
	/// <param name="transformList">
	/// The <see cref="Transform[]"/> of all objects to be aligned
	/// </param>
	public static void CenterInScreen(Transform[] transformList, Camera camera) {
		
		// Get a ray from the center of the camera
		Ray screenRay = camera.ScreenPointToRay(new Vector3(camera.pixelWidth/2, camera.pixelHeight/2, 0));
		float distance;
		
		foreach (Transform nextTransform in transformList) {
			// Create a plane from the object coordinates and the camera (as a normal)
			Plane objectPlane = new Plane(screenRay.direction, nextTransform.position);
			// Cast the ray from the camera to the object plane
			if (objectPlane.Raycast(screenRay, out distance)) {
				nextTransform.position = screenRay.GetPoint(distance);
			}
		}
	}
コード例 #48
0
ファイル: PlayerInput.cs プロジェクト: holemcross/ggj14-onyx
	void HandleScreenClick( Camera cam )
	{
		Debug.Log("In HandleScreenClick Update");
		float dist = 5000.0f;
		// Get Point Click
		
		Ray ray = cam.ScreenPointToRay(Input.mousePosition);
		RaycastHit hit;
		if(Physics.Raycast (ray, out hit, dist))
		{
			Debug.DrawLine(ray.origin, hit.point);
		}
		
		Debug.Log(hit.point);
		pawnController.SetWayPoint(new Vector3(hit.point.x,0,0), ownership);
	}
コード例 #49
0
ファイル: HUD.cs プロジェクト: rusticgames/rts
    public ScreenPointToWorldInfo GetWorldInfoAtScreenPoint(Vector3 screenPoint, Camera perspective)
    {
        if(	UnityEngine.Time.frameCount > freshestFrame ) {
            freshestFrame = UnityEngine.Time.frameCount;

            hitInfo = new RaycastHit();
            ray = perspective.ScreenPointToRay(screenPoint);
            infoThisFrame = new ScreenPointToWorldInfo();
            if(Physics.Raycast(ray, out hitInfo)) {
                infoThisFrame.isValid = true;
                infoThisFrame.worldPoint = hitInfo.point;
                infoThisFrame.objectAtPoint = hitInfo.collider.gameObject;
            }
        }
        return infoThisFrame;
    }
コード例 #50
0
        private void FixedUpdate()
        {
            if (_curInstance != null)
            {
                _healthPoint = (int)_curInstance.healtPoint;
                _maxHp       = (int)_curInstance.maxHp;

                _healthBar.UpdateBar(_healthPoint, _maxHp);

                if (_healthPoint <= 0)
                {
                    _healthBar.transform.parent.gameObject.SetActive(false);
                }
            }

            if (Input.GetMouseButtonDown(0))
            {
                Ray ray = _mainCamera.ScreenPointToRay(Input.mousePosition);

                RaycastHit hitObj;

                int layerMask = 1 << 10 | 1 << 9;

                if (Physics.Raycast(ray, out hitObj, Mathf.Infinity, layerMask))
                {
                    //if (hitObj.transform.tag.Equals("Enemy"))
                    //{
                    //    _npcCam.SetActive(false);
                    //    _enemyCam.SetActive(true);

                    //    InteractWithNpc(hitObj.transform.GetComponent<NpcController>());
                    //}

                    if (hitObj.transform.tag.Equals("NettralityNpc"))
                    {
                        hitObj.transform.GetComponent
                        <NeutralityNpcController>().CheckDistanceWithPlayer();

                        _npcCam.SetActive(true);
                        _enemyCam.SetActive(false);

                        InteractWithNpc(hitObj.transform.GetComponent <NpcController>());
                    }
                }
            }
        }
コード例 #51
0
ファイル: Input.cs プロジェクト: Thyrean/game_towerdefense
        //This is no callback and has to be invoked by another script
        public void Update()
        {
            RaycastHit hit;

            UnityEngine.Camera cam = UnityEngine.Camera.main;
            if (!cam)
            {
                Debug.LogError("Input.MouseWorldPosition: Main camera not found!");
                mouseWorldPosition = Vector3.zero;
            }
            Ray ray = cam.ScreenPointToRay(UnityEngine.Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                mouseWorldPosition = hit.point;
            }
            mouseWorldPosition = Vector3.zero;
        }
コード例 #52
0
        /*Vector3 ClosestPointOBB(BoxCollider collider, Vector3 target)这个版本的函数有bug,无效果
         * {
         *  // Cache the collider transform
         *  var ct = collider.transform;
         *
         *  // Firstly, transform the point into the space of the collider
         *  var local = ct.worldToLocalMatrix.MultiplyPoint3x4(target);
         *
         *  // Now, shift it to be in the center of the box
         *  local -= collider.center;
         *
         *  // Inverse scale it by the colliders scale
         *  var localNorm =
         *      new Vector3(
         *          Mathf.Clamp(local.x, -collider.size.x, collider.size.x),
         *          Mathf.Clamp(local.y, -collider.size.y, collider.size.y),
         *          Mathf.Clamp(local.z, -collider.size.z, collider.size.z)
         *      );
         *
         *  // Now we undo our transformations
         *  localNorm += collider.center;
         *
         *  // Return resulting point
         *  return ct.localToWorldMatrix.MultiplyPoint3x4(localNorm);
         * }*/

        /// <summary>
        /// 获得pointer指向的对象
        /// </summary>
        public GameObject GetPointerObject(LayerMask layerMask)
        {
            UnityEngine.Camera mainCam = UnityEngine.Camera.main;
            if (mainCam == null)
            {
                return(null);
            }

            Ray        ray = mainCam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;

            if (Physics.Raycast(ray, out hitInfo, float.PositiveInfinity, layerMask))
            {
                return(hitInfo.collider.gameObject);
            }

            return(null);
        }
コード例 #53
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100))
            {
                agent.SetDestination(hit.point);
            }
        }

        if (GameObject.FindGameObjectsWithTag("Limb").Length == 6)
        {
            Debug.Log("Fly away to magenta heaven");
            rb.MovePosition(transform.position + transform.up * Time.fixedDeltaTime);
        }
    }
コード例 #54
0
ファイル: TargetSelector.cs プロジェクト: wchoujaa/RTS
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             if (hit.transform.CompareTag(targetsTag))
             {
                 cam.SetTarget(hit.transform);
             }
             else
             {
                 cam.ResetTarget();
             }
         }
     }
 }
コード例 #55
0
        /// <summary>
        /// Check if given vertext is visible form current camera position.
        /// It is done by recast to small spehere collider placed at vertex position.
        /// </summary>
        /// <returns><c>true</c>, if vertex visibility was checked, <c>false</c> otherwise.</returns>
        /// <param name="vertex">Vertex.</param>
        public static bool CheckVertexVisibility(Vector3 vertex, UnityEngine.Camera camera, Vector3 scrennPoint)
        {
            var col = collider;

            col.enabled            = true;
            col.transform.position = vertex;

            var        camPos = camera.transform.position;
            RaycastHit hit;
            Ray        ray = camera.ScreenPointToRay(scrennPoint);

            if (Physics.Raycast(ray, out hit, 1000f, 1, QueryTriggerInteraction.Collide))
            {
                col.enabled = false;
                return(hit.collider == collider);
            }

            col.enabled = false;
            return(false);
        }
        void OnPick(Vector3 position, Action <List <Tuple <GameObject, RaycastHit> > > onPickCallBack)
        {
            if (m_MainCamera == null || !m_MainCamera.gameObject.activeInHierarchy)
            {
                m_MainCamera = UnityEngine.Camera.main;
                if (m_MainCamera == null)
                {
                    Debug.LogError($"[{nameof(MarkerAnchorSelector)}] active main camera not found!");
                    return;
                }
            }

            Ray ray = m_MainCamera.ScreenPointToRay(position);

            if (m_VREnableGetter())
            {
                ray.origin    = m_RightController.position;
                ray.direction = m_RightController.forward;
            }
            AnchorPicker.Pick(ray, onPickCallBack);
        }
コード例 #57
0
        private void Update()
        {
            var mousePos = Input.mousePosition;

            _rayMouse = _mainCamera.ScreenPointToRay(mousePos);

            if (Physics.Raycast(_rayMouse.origin, _rayMouse.direction, out _hit, hitLayerMasks))
            {
                if (_hit.transform.CompareTag("ChangeCube") || _hit.transform.CompareTag("InfoCube"))
                {
                    if (!_lock)
                    {
                        tooltipHandler.EnableTooltip(_hit.transform);
                        _lock        = true;
                        _activeObjId = _hit.transform.GetInstanceID();
                    }
                }
                else
                {
                    if (_lock)
                    {
                        _lock = false;
                        tooltipHandler.DisableTooltip();
                    }
                }

                if (_activeObjId != _hit.transform.GetInstanceID())
                {
                    _lock = false;
                }

                _correctedPos = _hit.point - new Vector3(0, 1.95f, 0);
                RotateToMouseDirection(gameObject, _correctedPos);
            }
            else
            {
                _correctedPos = _rayMouse.GetPoint(maximumLength) - new Vector3(0, 1.95f, 0);
                RotateToMouseDirection(gameObject, _correctedPos);
            }
        }
コード例 #58
0
        void UpdateMovement()
        {
            Ray ray = _mainCamera.ScreenPointToRay(Input.mousePosition);

            RaycastHit hitObj;

            int layerMask = 1 << 8;

            layerMask = ~layerMask;

            if (Input.GetMouseButtonDown(1))
            {
                if (Physics.Raycast(ray, out hitObj, Mathf.Infinity, layerMask))
                {
                    // _nav.destination = hitObj.transform.position;
                }
            }

            Move();
            Jump();
            Rotate();
        }
コード例 #59
0
    public void PlaceBuilding(BuildController build)
    {
        if (manager.resources > 0)
        {
            List <BuildController.BuildType> requiresToList = build.requires.ToList();
            //Debug.Log(requiresToList.ToString());
            foreach (BuildController presentBuild in manager.listBuild)
            {
                if (presentBuild.Active())
                {
                    requiresToList.Remove(presentBuild.type);
                }
                //Debug.Log(requiresToList.Count + " "+ presentBuild.type);
            }

            if (requiresToList.Count == 0)
            {
                Ray     ray = mainCamera.ScreenPointToRay(Input.mousePosition);
                Vector3 pos;
                if (Physics.Raycast(ray: ray, hitInfo: out RaycastHit hit, layerMask: LayerMask.GetMask("Default"),
                                    maxDistance: 1000))
                {
                    pos = hit.point;
                }
                else
                {
                    pos = Vector3.zero;
                }
                BuildController toBuild = Instantiate(build, pos, Quaternion.identity);
                state.ConstructState(toBuild);
            }
            else
            {
                //TODO Feedback build require
            }
        }
コード例 #60
0
ファイル: Pseudo3D.cs プロジェクト: kurumsaleyup/FPSGame
        /// <summary>
        /// Returns the delta yaw rotation of the character.
        /// </summary>
        /// <param name="characterHorizontalMovement">The character's horizontal movement.</param>
        /// <param name="characterForwardMovement">The character's forward movement.</param>
        /// <param name="cameraHorizontalMovement">The camera's horizontal movement.</param>
        /// <param name="cameraVerticalMovement">The camera's vertical movement.</param>
        /// <returns>The delta yaw rotation of the character.</returns>
        public override float GetDeltaYawRotation(float characterHorizontalMovement, float characterForwardMovement, float cameraHorizontalMovement, float cameraVerticalMovement)
        {
#if UNITY_EDITOR
            if (m_LookSource == null)
            {
                Debug.LogError("Error: There is no look source attached to the character. Ensure the character has a look source attached. For player characters the look source is the Camera Controller, and AI agents use the Local Look Source.");
                return(0);
            }
#endif
            if (m_LookInMoveDirection)
            {
                if (characterHorizontalMovement != 0 || (m_AllowDepthMovement ? characterForwardMovement : 0) != 0)
                {
                    var inputVector = Vector3.zero;
                    inputVector.Set(characterHorizontalMovement, 0, (m_AllowDepthMovement ? characterForwardMovement : 0));
                    Quaternion lookRotation;
                    if (m_Path != null)
                    {
                        lookRotation = Quaternion.LookRotation(Quaternion.LookRotation(Vector3.Cross(m_Path.GetTangent(m_Transform.position, ref m_PathIndex), m_CharacterLocomotion.Up)) * inputVector.normalized);
                    }
                    else
                    {
                        lookRotation = Quaternion.LookRotation(m_LookSource.Transform.rotation * inputVector.normalized);
                    }
                    return(MathUtility.ClampInnerAngle(MathUtility.InverseTransformQuaternion(m_Transform.rotation, lookRotation).eulerAngles.y));
                }
            }
            else
            {
                // The character should look towards the cursor or Mouse X/Y direction.
                if (m_PlayerInput.IsCursorVisible())
                {
                    var     characterCenter = m_Transform.position + (m_CharacterLocomotion.Up * m_CharacterLocomotion.Height / 2);
                    Vector3 forward;
                    if (m_Path != null)
                    {
                        forward = Vector3.Cross(m_Path.GetTangent(m_Transform.position, ref m_PathIndex), m_CharacterLocomotion.Up);
                    }
                    else
                    {
                        forward = m_LookSource.Transform.forward;
                    }
                    var localLookDirection = m_Transform.InverseTransformDirection(forward);
                    // The vertical look direction can be ignored.
                    localLookDirection.y = 0;
                    m_HitPlane.SetNormalAndPosition(m_Transform.TransformDirection(localLookDirection), characterCenter);

                    // Cast a ray from the mouse position to an invisible plane to determine the direction that the character should look.
                    float distance;
                    var   ray = m_Camera.ScreenPointToRay(m_PlayerInput.GetMousePosition());
                    if (m_HitPlane.Raycast(ray, out distance))
                    {
                        // Only rotate the character if the mouse is far enough away from the character's origin.
                        var localHitPoint = m_Transform.InverseTransformPoint(ray.GetPoint(distance));
                        localHitPoint.y = 0;
                        if (localHitPoint.magnitude > (m_LookRotateBuffer * Mathf.Max(1, m_CharacterLocomotion.LocomotionVelocity.magnitude)) || m_InitialOrientation)
                        {
                            // The character should only rotate along the local y axis. This can be done by zeroing out the y direction after the character center is subtracted.
                            localHitPoint.y = m_CharacterLocomotion.Height / 2;
                            var rotation = Quaternion.LookRotation((m_Transform.TransformPoint(localHitPoint) - characterCenter).normalized, m_CharacterLocomotion.Up);
                            return(MathUtility.ClampInnerAngle(MathUtility.InverseTransformQuaternion(m_Transform.rotation, rotation).eulerAngles.y));
                        }
                    }
                }
                else
                {
                    // If the mouse hasn't moved then get the axis to determine a look rotation. This will be used for controllers and virtual input.
                    var direction = Vector3.zero;
                    direction.x = m_PlayerInput.GetAxis(m_PlayerInput.HorizontalLookInputName);
                    direction.z = m_PlayerInput.GetAxis(m_PlayerInput.VerticalLookInputName);
                    if (direction.sqrMagnitude > 0.1f)
                    {
                        var rotation = Quaternion.LookRotation(direction.normalized, m_CharacterLocomotion.Up);
                        return(MathUtility.ClampInnerAngle(MathUtility.InverseTransformQuaternion(m_Transform.rotation, rotation).eulerAngles.y));
                    }
                }
            }

            return(0);
        }