This script is attached to a empty game object and a gun attached to it, on forward movement its very jittery.
I am thinking if I can add the line of code to a smoothDamp function it will fix the issue problem I am having is converting a vector3 to a float.
I also tried slerp but not sure what to set the second Quaternion too.
here is the code
public GameObject cameraObject;
public float smoothSpeedRotation = 0.5f;
public float holdHeight = -0.42f;
public float holdSide = 0.42f;
//public float holdForward = 0.1f;
float targetXRotation;
float targetYRotation;
float targetXRotationVelocity;
float targetYRotationVelocity;
// Update is called once per frame
void Update () {
//effecting the transform of the gun.
transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0)* new Vector3(holdSide,holdHeight,0));
//smothly effect the guns rotation
targetXRotation = Mathf.SmoothDamp(targetXRotation,cameraObject.GetComponent<MouseLookScript>().rotationX,ref targetXRotationVelocity,smoothSpeedRotation);
targetYRotation = Mathf.SmoothDamp(targetYRotation,cameraObject.GetComponent<MouseLookScript>().rotationY,ref targetYRotationVelocity,smoothSpeedRotation);
//physically move the gun
transform.rotation = Quaternion.Euler(targetXRotation,targetYRotation,0);
}