I want the flashlight to look same while looking up and down as when looking straight.

Normal Position for Hand and flashlight: enter image description here

Looking up and down, position is completely off: enter image description here enter image description here

More images for character/camera prefab rotation: enter image description here enter image description here

Basically the position of the Hand held flashlight changes when I look up or down, as well as the arm stretches. How do I fix this?

Code for character rotation:

private void CharacterRotation()
    float posX = Input.GetAxis(mouseX) * ((StructsInitializers.Sensitivity * 5) + StructsInitializers.Sensitivity*50) * Time.deltaTime;
    float posY = Input.GetAxis(mouseY) * ((StructsInitializers.Sensitivity * 5) + StructsInitializers.Sensitivity*50) * Time.deltaTime;
    yAxisClamp += posY;

    if(yAxisClamp > 90.0f)
        yAxisClamp = 90.0f;
        posY = 0.0f;
    else if(yAxisClamp < -90)
        yAxisClamp = -90.0f;
        posY = 0.0f;
    transform.Rotate(Vector3.left * posY);
    PlayerBody.Rotate(Vector3.up * posX);

private void ClampYAxisRotation(float value)
    Vector3 eulerRotation = transform.eulerAngles;
    eulerRotation.x = value;
    transform.eulerAngles = eulerRotation;

PS: I am new to game developing. I have lack of experience.

  • \$\begingroup\$ Do you have a non-uniform scale on the parent object that contains your camera and arm? \$\endgroup\$
    – DMGregory
    May 3 '19 at 2:06
  • \$\begingroup\$ I'm not sure, how do I find that out? PS: I'm new at game developing so I lack experience. \$\endgroup\$
    – Sup Boy
    May 3 '19 at 2:14
  • \$\begingroup\$ Click on it and look at the scale values of the Transform component in the inspector. You're looking for one value (probably y) that's different from the others. \$\endgroup\$
    – DMGregory
    May 3 '19 at 2:15
  • \$\begingroup\$ I test played, and I was rotating to see. No values change in HandHeld Flashlight prefab. So I think that's the issue. \$\endgroup\$
    – Sup Boy
    May 3 '19 at 2:18
  • \$\begingroup\$ What you describe is not the way to diagnose this particular problem. A non-uniform scale inherited from a parent will not be shown in the inspector when you select the child object. \$\endgroup\$
    – DMGregory
    May 3 '19 at 2:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.