Hello everybody! So I have a small problem with a script which add some movements to the gun when you move your mouse around, the problem is that the gun rotate to much when I move the mouse, for exemple, see this screenshot, it show what happen when I move the mouse to the left, it’s the same for the right, up and down:
Thanks! I forgot to remove this, this is something I wrote when I was trying to fix the bug, so I removed it but it doesn’t fix my bug! Here is my new code:
var speed : float;
var multiplier : float;
private var moveOnX : float;
private var moveOnY : float;
private var originPos : Vector3;
function Start() {
originPos = transform.localPosition;
}
function FixedUpdate () {
moveOnX = Input.GetAxis( "Mouse X" ) * Time.deltaTime;
moveOnY = Input.GetAxis( "Mouse Y" ) * Time.deltaTime;
var lookAt : Vector3 = originPos - Vector3(originPos.x + moveOnX, originPos.y + moveOnY, originPos.z);
transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.LookRotation(lookAt), speed * Time.deltaTime);
}
Saw this looking for something else. Future warnings intended. Never multiply your camera rotation factor (from axis like mouse) by Time.deltatime. Time.deltatime is a factor to fit the movement into FPS basis. If you want your player to move 10 units per second, you do 10*Time.deltaTime; You’re essentially trying to do MousePosition = Cursor change per second; Cursor Change resets every frame! To fix this script appropriately, remove the Time factors on line 15/16, go into your unity input settings for Mouse X and Mouse Y, and lower the sensitivity. Alternatively, create a mouse sensitivity buffer (0-1 based) to multiply against the the GetAxis results from mouse input. Although this may play perfectly find in most cases you run it in, as soon as another computer, or device tries to run this, the camera will move far slower, or faster, depending on the system specs. If you want to quick-test these results, run it without vsync.