- Home /
Question by
TheRichardGamer · Oct 11, 2013 at 09:04 AM ·
gunglitchsway
Gun sways way too much
My gun sway script can make my gun sway up too much so you can see that the arms are fake and that the weapon is fake as well. How do I make so that it doesn't do this?
Here's the sway script:
var amount : float = 0.02;
var maxAmount : float = 0.03;
var Smooth : float = 3;
var SmoothRotation = 2;
var tiltAngle = 25;
private var def : Vector3;
function Start ()
{
def = transform.localPosition;
}
function Update ()
{
var factorX : float = -Input.GetAxis("Mouse X") * amount;
var factorY : float = -Input.GetAxis("Mouse Y") * amount;
if (factorX > maxAmount)
factorX = maxAmount;
if (factorX < -maxAmount)
factorX = -maxAmount;
if (factorY > maxAmount)
factorY = maxAmount;
if (factorY < -maxAmount)
factorY = -maxAmount;
var Final : Vector3 = new Vector3(def.x+factorX, def.y+factorY, def.z);
transform.localPosition = Vector3.Lerp(transform.localPosition, Final, Time.deltaTime * Smooth);
var tiltAroundZ = Input.GetAxis("Mouse X") * tiltAngle;
var tiltAroundX = Input.GetAxis("Mouse Y") * tiltAngle;
var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
transform.localRotation = Quaternion.Slerp(transform.localRotation, target,Time.deltaTime * SmoothRotation);
}
Comment
Have you tried tuning down the variables in the script?
Note the values in the script are public which means changing the values in the script after the script is attached to the object will not change the values used by Unity. You must change them in the inspector.
Your answer
Follow this Question
Related Questions
Aim Down Sights and Weapon Sway not working unless animations are not assigned 0 Answers
Animation & Script Help 2 Answers
How do i make my weapon sway? 2 Answers
Gun Sway Script Not Working Properly on Start 1 Answer
Weird problem with gunscript 2 Answers