Problem with 1.8 Basic Gun with Weight
On my Gunscript everything works great but a gun do not have good smooth, its jitter. I tried to put the whole code in LateUpdate() and just targetXRotation, targetYRotation in LateUpdate() but gun still has the jitter. When I put targetXRotation, targetYRotation in LateUpdate() a gun have smaller jitter but it still have. Can anyone help on this problem? Master how to solve this? Is it up to my pc that is slow. Maybe is framerates? Please help the teacher.
Btw. Your videos is great. I like that you go in so details.
Code:
var cameraObject:GameObject;
@HideInInspector
var targetXRotation:float;
@HideInInspector
var targetYRotation:float;
@HideInInspector
var targetXRotationV:float;
@HideInInspector
var targetYRotationV:float;
var speedOfRotationSmooth:float = 0.5;
var gunHoldSide:float = 0.5;
var gunHeightSide:float = -0.5;
var gunForwardSide:float = 0.5;
function Update ()
{
transform.position = cameraObject.transform.position + (Quaternion.Euler(0, targetYRotation, 0) * Vector3(gunHoldSide, gunHeightSide, gunForwardSide));
/*targetXRotation = Mathf.SmoothDamp(targetXRotation, cameraObject.GetComponent(MouseLook).XRotation, targetXRotationV, speedOfRotationSmooth);
targetYRotation = Mathf.SmoothDamp(targetYRotation, cameraObject.GetComponent(MouseLook).YRotation, targetYRotationV, speedOfRotationSmooth);*/
transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
//transform.rotation *= Time.deltaTime;
}
function LateUpdate()
{
targetXRotation = Mathf.SmoothDamp(targetXRotation, cameraObject.GetComponent(MouseLook).XRotation, targetXRotationV, speedOfRotationSmooth);
targetYRotation = Mathf.SmoothDamp(targetYRotation, cameraObject.GetComponent(MouseLook).YRotation, targetYRotationV, speedOfRotationSmooth);
}