- Home /
Get input strength from mouse movement?
Hi. I'm trying to get my mouse to rotate my camera proportional to how much I move my mouse.
if(Input.GetAxis("Mouse X") > 0) {
transform.Rotate(Vector3.up * Sensitivity * Time.deltaTime);
}
if (Input.GetAxis ("Mouse X") < 0) {
transform.Rotate (Vector3.down * Sensitivity * Time.deltaTime);
}
if (Input.GetAxis ("Mouse Y") > 0) {
transform.Rotate (Vector3.left * Sensitivity * Time.deltaTime);
}
if(Input.GetAxis("Mouse Y") < 0) {
transform.Rotate(Vector3.right * Sensitivity * Time.deltaTime);
}
The vectors are correct (In case you're wondering). The problem is that no matter how quickly you move the mouse, the camera rotates at the same speed. I need it to be like this: If you move your mouse slowly, the camera will spin slowly, and if you move your mouse quickly, your camera will rotate quickly.
Thanks for any help :D
Answer by mptp · Aug 04, 2015 at 07:22 AM
The reason this is happening is because you aren't using the axis value in the value you're passing to transform.Rotate. Input.GetAxis() will return a variable float value corresponding to how much the mouse has moved i.e. how fast it's moving.
Try something like:
float mouseX = Input.GetAxis("Mouse X");
if(mouseX > 0) {
transform.Rotate(Vector3.up * Sensitivity * mouseX * Time.deltaTime;
}
And so on.
Your answer
Follow this Question
Related Questions
How to rotate a gameobject (Y Axis) via c#? 2 Answers
rotate camera on mouse reaching edges 1 Answer
Camera movement independent of player control 1 Answer
Select/Drag/Drop Objects with a mouse 0 Answers
using left right keys to turn 1 Answer