Mouse Rotation Help
Hello, I am fairly new to Unity, and am stuck on an issue I have previously solved in Game-maker. I am trying to get an object to follow the mouse, clamped with a magnitude to restrict the amount it will follow the mouse away from the center object. I have tried to use transform.RotateAround and the mouse but cannot get it to stop at the angle from the center object to the mouse.
Here is what I have in Game-maker (What I want to make in Unity) https://gfycat.com/JovialRelievedIndochinesetiger
And the issue in Unity
https://gfycat.com/SelfreliantVengefulHoki
This is code that I have:
     // Get mouse position
     Vector3 mPos = Input.mousePosition;
     mPos.z = transform.position.z - Camera.main.transform.position.z; 
     mPos = Camera.main.ScreenToWorldPoint(mPos);
     // Get 360 Degrees between main object and mouse
     test = Vector2.Angle(transform.position, mPos);
     test2 = Mathf.Atan2(mPos.y, mPos.x) * Mathf.Rad2Deg;
     Debug.Log(test2);
     Vector3 dir2 = mPos;
     float radius = .05f;
     // Clamp magnitude to radius from player
     dir2 = Vector3.ClampMagnitude(dir2, radius);
     // Set position
     dir2.y = .065f;
     rightObj.position = transform.position + (dir2);
Your answer
 
 
             Follow this Question
Related Questions
Object can't get to the target point 0 Answers
Get Velocity of Rigidbody Object Below Another Object 0 Answers
3D FPS to 2D mouse 1 Answer
iscometric grid panning 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                