Hi, I'm creating a first person shooter and I am having trouble getting the gun and the player to rotate how I want them to rotate.
First of all, the player looks like this:
When I move my mouse, I want the gun and camera to rotate both horizontally vertically and the player itself to only move horizontally (since vertical rotations will cause it to look weird). Since the player object is a parent of both the gun and camera, I can't make this possible.
I tried using this:
transform.rotation = Quaternion.Euler(0, xRot, 0);
camera.transform.rotation = Quaternion.Euler (yRot, 0, 0);
However, whenever I do that the player rotates horizontally without the camera and gun following.
How can I fix this problem?
Edit: I tried creating an empty gameobject and making it a parent of the gun, but I still can't get it to work..
Edit 2: Ok, I did some research and I made two separate scripts to move each part of the player, but one cancels out the other and at the end the result is the same
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
119 People are following this question.
Rotate Rigidbody on Y Axis based on Velocity on X and Z axis
How to rotate Object with Mouse drag (specifications below)
Change rotation sensitivity of Oculus Rift?
How do you maintain gravity using transform.forward and transform.right?
Trying to simulate roll of character's body down a luge slide