0
\$\begingroup\$

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;
        ClampYAxisRotation(270.0f);
    }
    else if(yAxisClamp < -90)
    {
        yAxisClamp = -90.0f;
        posY = 0.0f;
        ClampYAxisRotation(90.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.

\$\endgroup\$
5
  • \$\begingroup\$ Do you have a non-uniform scale on the parent object that contains your camera and arm? \$\endgroup\$ Commented May 3, 2019 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\$ Commented May 3, 2019 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\$ Commented May 3, 2019 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\$ Commented May 3, 2019 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\$ Commented May 3, 2019 at 2:20

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.