- Home /
FPS weapon sway script error
I'm making my first FPS game and I'm using this script for weapon sway:
var cameraObject : GameObject;
@HideInInspector
var targetXRotation : float;
@HideInInspector
var targetYRotation : float;
@HideInInspector
var targetXRotationV : float;
@HideInInspector
var targetYRotationV : float;
var rotateSpeed : float = 0.3;
var holdHeight : float = -0.5;
var holdSide : float = 0.5;
function Update ()
{
transform.position = cameraObject.transform.position +(Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide,holdHeight,0));
targetXRotation = Mathf.SmoothDamp(targetXRotation,cameraObject.GetComponent(MouseLook).xRotation, targetXRotationV, rotateSpeed);
targetYRotation = Mathf.SmoothDamp(targetYRotation,cameraObject.GetComponent(MouseLook).yRotation, targetYRotationV, rotateSpeed);
transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation,0);
}
and I get this error:
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible) Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value) Boo.Lang.Runtime.RuntimeServices.UnboxSingle (System.Object value) GunScriptE.Update () (at Assets/Scripts/GunScriptE.js:21)
My gun behaviour is very strange now. How can I fix this because no matter what I try, it won't work! I'm new here so I apologize that! Thanks
Do you have a component $$anonymous$$ouseLook on the camera object ? You can see it if you select the camera object, and check if the component appears in the inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220613102404im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why is this player script not working 1 Answer
GUI Scale Problem 1 Answer
[Closed] MainMenu Script error 2 Answers
Error BCE0051: Operater '==' cannot be used. Please Help! 1 Answer
what is wrong with this online FPS script(not done) ? 1 Answer