Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Need help with my gun movement script

$
0
0
So I have been following a tutorial series by ETeeski Tutorials, and I got stuck on fps 1.8. AKA scripting a basic gun with weight. This is the script: #pragma strict var cameraObject : GameObject; var rotationSpeed : float = 0.3; @HideInInspector var targetXRotation : float; @HideInInspector var targetYRotation : float; @HideInInspector var targetXRotationV : float; @HideInInspector var targetYRotationV : float; var holdSide : float = 0.5; var holdHeight : 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(MouseLookScript).xRotation, targetXRotationV, rotationSpeed); targetYRotation = Mathf.SmoothDamp(targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotationSpeed); transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0); } I understand that the u set the position of the gun to follow the camera's position and then move it to a certain position using the Vector3. But if you are going to set the rotation of the Vector3 here, why use the variable "targetYRotation"? I don't really understand this part of the code and all help will be appreciated. Thanks!

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>