• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RealSoftGames · Jun 12, 2015 at 01:51 PM · rotationquaternion

rotation not working (maybe conflicting with mouselook script)

hi guys i have a silly question to ask that should be easy to answer but nothing is working, after diagnosing for a few days i have decided to post my problem up here for some help to try and figure out why this wont work.

here is my mouse look script, this works perfectly fine for now. the issue is i want to animate the camera for my FPS game with some recoil and other basic things.

 using UnityEngine;
 using System.Collections;
 
 public class MouseLook : MonoBehaviour {
 
     public float sensetivity = 5f;
     public float yRotation;
     public float xRotation;
     public float curXRot, curYRot;
     public float yRotV,xRotV;
     public float Smoothness = 0.1f;
 
     public bool MouseX,MouseY;
     
     void Update(){
 
         if (MouseY) {
             yRotation += Input.GetAxis ("Mouse X") * sensetivity;
             curYRot = Mathf.SmoothDamp (curYRot, yRotation, ref yRotV, Smoothness);
             transform.rotation = Quaternion.Euler (xRotation,yRotation, 0);
         }
 
         if(MouseX)
         {
             xRotation -= Input.GetAxis ("Mouse Y") * sensetivity;
             curXRot = Mathf.SmoothDamp (curXRot, xRotation, ref xRotV, Smoothness);        
             transform.rotation = Quaternion.Euler (xRotation,yRotation, 0);
             xRotation = Mathf.Clamp(xRotation, -90, 90);
         }
 
 
     }    
     
 }
 

i had tried to just firstly rotate the camera on the X axis with (I tried it in both update and lateUpdate) i thought it could be conflicting with my mouselook script. and i have a good feeling it is conflicting iwth it, what happens is the rotation starts and flickers. i had put the same code on a cude and it rotates perfectly. my initial goal with this rotation is to add it to a recoil effect. on the X and Y axis. this is to rotate the camera by the way.

void LateUpdate() { transform.Rotate(0,20*Time.deltaTime,0); }

much appreciate the input to help resolve the rotation error i'm getting.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Radetic · Jun 12, 2015 at 02:24 PM

Try having the camera as child to the game object taking the recoils and other effects.

Use transform.localRotation in the MouseLook script to ensure the parent and child rotations will compose instead of the camera overrinding all information from above in the hierarchy.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RealSoftGames · Jun 12, 2015 at 03:57 PM 0
Share

Ihave my fps hands parented and animated to the camera my heirarchy is like this Player (empty gameobject) Camera Fps hands and weapons that's the order of my player steucture,mouse look on the x axis for camera. And another on the player object to rotate the Y axis. The issue is the mouse script over riding everything on my camera. I believe this is the issue. I could be wrong

avatar image Radetic · Jun 12, 2015 at 04:16 PM 0
Share

So, here is a possible solution from what I would try:

Player (moves and turns)

  • weapons (aim where the player is headed)

  • effects (shake, twist, pitch, roll, yaw etc)

  • camera (aim with mouse look) as child of effects

  • hands as child of effects

avatar image RealSoftGames · Jun 12, 2015 at 04:19 PM 0
Share

I beleive this may be a solution patenting the camera to an empty game object and applying the effects to that. But its just patching the problem. Their is definatly something wrong with my script.

avatar image Radetic · Jun 12, 2015 at 04:27 PM 0
Share

I don't think of it as a patch... when you get hit, your body shakes and you still control your head. Your body is the parent and your head is free to change it's local rotation.

That's the only thing to change in your script perhaps. Use localRotation ins$$anonymous$$d of rotation to insure effects on the parents will get through to the camera.

avatar image RealSoftGames · Jun 12, 2015 at 04:29 PM 0
Share

Ahh I didn't think about that ill give it a go when I wake up. Will post back if I get any changes.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Quaternion Rotation On Specific Axis Issue 0 Answers

Calculate rotation angle for two side of cube ( like dice ) from Quaternion.identity 0 Answers

Look at like rotating around y axis 1 Answer

ConfigurableJoint - angular positions (rotation) problem 1 Answer

Make Quaternion affected by float 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges