- Home /
Gun Sway Script glitching
I have the same script attached to 3 different weapons, and the first weapon just persists when I swap weapons. What do I do?
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("$$anonymous$$ouse X") amount; var factorY : float = -Input.GetAxis("$$anonymous$$ouse 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("$$anonymous$$ouse X") * tiltAngle;
var tiltAroundX = Input.GetAxis("$$anonymous$$ouse Y") * tiltAngle;
var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
transform.localRotation = Quaternion.Slerp(transform.localRotation, target,Time.deltaTime * SmoothRotation);
}
The sway script isnt the problem, it will be the swap script, can i see that please
Can't see anything wrong in this script, everything is doing what it should do. It is a gues, but i think you have to disable the first weapon in the swap script before enabling the second one. That way the previous weapon won't execute the script.
But to think of it, isn't it easier just animating it and then play/pause the animation.
Your answer
Follow this Question
Related Questions
Mouse look alteration? 1 Answer
Gun sway script not working 2 Answers
Problem with quaternion weapon sway 1 Answer
Mouse Script Reversed (y and x axis) 1 Answer
Gun sways way too much 0 Answers