How to set the rotation of an object to that of another object with a offset?

391 Views Asked by At

im having problems with my game, i want to have a pistol orbit around my charecter and the position is allready done by a joint. however the joint doesn't rotate the object so i try to do that by code, but the problem is that i need to set an offset becouse the gun is 90degrees rotated around the y axes but than a weird thing happens.

i made a video to damonstrate this: https://youtu.be/HxNj6keyQ5U

i don't know how to fix this and i tryed everything.

thanks for your awnsers! (if i get any xD)

here's the code:

    {
        EulerRotation = new Vector3(Player.transform.rotation.eulerAngles.x, Player.transform.rotation.eulerAngles.y - 90, Player.transform.rotation.eulerAngles.z);
        transform.rotation = Quaternion.Euler(EulerRotation);
    }

1

There are 1 best solutions below

0
MohammadReza Arashiyan On


if you are using Standard First Person Controller, It contains two parts: Main Object, Main Camera.
by a script, rotation on Y-axis is attached to Main Prefab, and rotation on the Z axis is attached to the Main camera. so when you use Player.transform.rotation.eulerAngles.z in fact you are using Z axis on Main Object and so it will never change.