- Home /
Mouse Follow Script Help
Hi all!! This is what I am trying to do.
I want the top half of my char with my 1st person camera to always trying to center on my mouse cursor at a slow rate (Like the top half of a Tank). then when I hit the tab key it will freeze the screen and the cursor will still move about the screen. I have looked at many mouse look scripts with no luck.
Thanks in advance!
I have been using Java but any kind of help would, well.... help.
Answer by Macdude2 · May 10, 2011 at 04:21 AM
For the 2D aiming, look at this question: http://answers.unity3d.com/questions/56458/2d-cursor-aiming
You could use the solution to that script and just restrict the maximum speed the tank is allowed to rotate.
For the second part, I do not quite understand. Do you want to pause the game with the tab key to pause the game? If so, then you can just do if(getkeydown("tab")){cancontrol = false;} with cancontrol being the variable that controls whether or not the mouse aims or does something else.
Im just looking to press the z key and have the screen stop following the mouse cursor. But i still want to move the cursor around the screen. I do not want to pause the game.
im using if (Input.Get$$anonymous$$ey ("z")) { GetComponent(Slow$$anonymous$$ove).enabled = false; }
if (Input.Get$$anonymous$$eyUp("z"))
{
GetComponent(Slow$$anonymous$$ove).enabled = true;
}
This is what Im using for the camera movement but it does not work properly.
var lookTarget : Vector3; var turnSpeed = 20.0;
function Update() {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
lookTarget = hit.point;
}
// rotate towards target
var lookDelta = (hit.point-transform.position);
var targetRot = Quaternion.LookRotation(lookDelta);
var rotSpeed = turnSpeed * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards( transform.rotation, targetRot, rotSpeed );