Question by
HigginDazs · Mar 30, 2017 at 09:21 PM ·
inputmouselock-cursor
Mouse cannot move when key is held down
I have a simple script to rotate the camera position based on where the mouse is using GetAxis for the mouse X and Y, but whenever any other key is held down or pressed, the mouse locks and cannot move until the key has been released. Is there any solution to this?
Edit: Added code for the camera and movement inputs. They are on two separate gameobjects
void FixedUpdate()
{
Rigidbody droneBody = GetComponent<Rigidbody>();
float moveLeftRight = Input.GetAxis("Strafe");
float moveForwardBack = Input.GetAxis("Vertical");
float moveHeight = Input.GetAxis("Elevate");
float spinAxis = Input.GetAxis("Horizontal");
moveDirection = new Vector3(moveLeftRight, moveHeight, moveForwardBack);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
droneBody.velocity = moveDirection;
droneBody.rotation = Quaternion.Euler(
0.0f,
(currentRotation += spinAxis * 2),
0.0f);
droneModel.transform.localEulerAngles = new Vector3(
moveForwardBack * speed * tilt,
0.0f,
moveLeftRight * speed * -tilt);
}
--------------------------------------------------------------------------
public class UndercarriageCamera : MonoBehaviour {
public float hSpeed;
public float vSpeed;
private float currentX = 0.0f;
private float currentY = 0.0f;
private float lockZ = 0.0f;
private void Update()
{
// reversed because of the axes of the camera relative to the scene
float camRotateX = hSpeed * Input.GetAxis("Mouse Y");
float camRotateY = vSpeed * Input.GetAxis("Mouse X");
if (GetComponent<Camera>().enabled)
{
transform.rotation = Quaternion.Euler(
currentX -= camRotateX,
currentY += camRotateY,
lockZ);
}
else
{
transform.rotation = Quaternion.Euler(
0.0f,
0.0f,
lockZ);
}
}
}
Comment
We should really see your script to identify the problem :]
Your answer
Follow this Question
Related Questions
Why is Input.GetMouseButtonUp(0) not returning true? 0 Answers
How to check if a player click on a object: Android Mobile 1 Answer
Mouse-Keyboard Not Working - New User 1 Answer
Left Mouse doesn't register click when keyboard button is pressed 1 Answer
How to detect how much was mouse moved only horizontaly? 1 Answer