Naddar Bhatia
Naddar Bhatia

Reputation: 33

Fixed the position of Gun

My gun position is not getting fixed, it is moving with rotation. Please see in the below pic.

Please see image

I am using the following code:

if (Input.GetMouseButton(1))
{
    if (countICR < 50)
    {
        GameObject.FindGameObjectWithTag("Gun").transform.Rotate(-8 * Time.deltaTime, 0, 0);
        countICR++;
        countDCR--;
    }
}

if (Input.GetMouseButton(2))
{
    if (countDCR < 50)
    {
        GameObject.FindGameObjectWithTag("Gun").transform.Rotate(8 * Time.deltaTime, 0, 0);
        countDCR++;
        countICR--;
    }
}

I have also tried using Rigidbody attached to the gun and freezing the position (all coordinates), but it still is changing.

I want the gun to be fixed at the handle side and the other parts should move up and down.

Upvotes: 2

Views: 114

Answers (1)

Le len
Le len

Reputation: 63

remove the script.. that is what makes the gun rotate ;)

you simply dont want the gun to rotate (so why script it?). you want the character to rotate, and the gun to listen.

make the gun a child of where it is supposed to be fixed to ( example: the hand ), then rotate the arm. the hand will follow, as will the gun.

ps: if you want to make it look good, use animations.

Upvotes: 2

Related Questions