Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by CherryHotaling · Nov 22, 2015 at 09:41 AM · cameraprefabfirst-person-controllerbonetilt

Tilting Head with Camera from the FirstPersonController Script FPS controller provided in (Unity 5)

Hello All, I am using the provided FPSController prefab provided with Unity 5 in the character assets. (I was making my own first person camera script but this provided more options)

I wanted the camera to effect the head bone of my character model. I want my character models head to tilt where I am moving my camera. What can I add to the script to do this?

Thank you for your time in advance!

Comment
Add comment · Show 2
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 CherryHotaling · Nov 22, 2015 at 05:01 PM 0
Share

If I parent the head to the "FirstPersonCharacter" camera, it will tilt etc but it obviously will not move on the proper axis, so the head will fly up and rotate etc.

I am guessing I need a script in the head bone that rotates on local axis to the bone, that follows the camera, any suggestions?

Thanks

avatar image CherryHotaling · Dec 02, 2015 at 01:07 AM 0
Share

Any help with this would be greatly appreciated! I am still learning and wanted to use the 1st person camera with a character model of $$anonymous$$e.

I created a separate script and put it in the head bone of the character.

The public variables headBone and cameraObject I dragged them from the Hierarchy into the inspector slots.

Here is my Script:

 using UnityEngine;
 using System.Collections;
 
 //FirstPersonCharacter
 //Character1_Head
 
 public class HeadLook : $$anonymous$$onoBehaviour {
 
     public Transform headBone;
     public Camera cameraObject;
 
     //var bizzyBone : Transform;
 
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
         headBone.rotation = cameraObject.localrotation;
     }
 
     void LateUpdate()
     {
 
     }
 
 }
 

I get an error: "Severity Code Description Project File Line Error CS1061 'Camera' does not contain a definition for 'localrotation' and no extension method 'localrotation' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?) 1st person camera.CSharp.Plugins D:\Unity Projects\1st person camera\Assets\Standard Assets\Characters\FirstPersonCharacter\Scripts\HeadLook.cs 22 "

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by CherryHotaling · Dec 10, 2015 at 02:11 AM

Ok Figured out how to Rotate the neck with the camera (The example below I had to have the X of the camera rotate the Z of the bone) Put this Script inside the head bone of your character:

 using UnityEngine;
 using System.Collections;
 
 public class HeadTiltWCamera : MonoBehaviour
 {
 
     public Camera cameraRot;
     private Vector3 objRot;
 
 
     // Use this for initialization
     void Start()
     {
         //Only take the x axis rotation
         //Bone only uses Z for up and down, camera oddly is using the X for up and down
         Vector3 tmp = cameraRot.transform.localEulerAngles;
         tmp = cameraRot.transform.localEulerAngles;
         tmp.x = 0f;
         tmp.y = 0f;
         tmp.z = -cameraRot.transform.localEulerAngles.x + 10.0f;
         objRot = tmp;
 
         transform.localEulerAngles = objRot;
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
     void LateUpdate()
     {
         //Only take the x axis rotation
         //Bone only uses Z for up and down, camera oddly is using the X for up and down
         Vector3 tmp = cameraRot.transform.localEulerAngles;
         tmp = cameraRot.transform.localEulerAngles;
         tmp.x = 0f;
         tmp.y = 0f;
         tmp.z = -cameraRot.transform.localEulerAngles.x + 10.0f;
         objRot = tmp;
 
         transform.localEulerAngles = objRot;
     }
 }
 

There is one problem, The camera will not move its position with the animation because OBVIOUSLY it is not parented to the head. The problem I have when I parent the camera to the head is the Minimum and Maximum X constraints do not work and the camera will rotate on weird angles. I suppose I should find a way to just make the neck do what the camera does with the FPS controller and have the camera move with the mouse movements. Or I could figure out why the camera is working oddly when parented to the head.

Well I figured I would post this for anyone that might be interested in this sort of thing.

Comment
Add comment · Show 1 · 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 CherryHotaling · Dec 10, 2015 at 05:31 AM 0
Share

I found out that the "$$anonymous$$ouseLook.cs" script from the FirstPersonController that comes with unity has a section in it that I changed to limit rotations. I basically bypassed the crazy math of the Quaternion at the bottom of the script. I changed around line 38s if statement for clampcertical rotation to this:

            if (clampVerticalRotation)
             {
                 character.localRotation = m_CharacterTargetRot;
 
                 //$$anonymous$$ake sure not to pass a certain angle
                 //Store the camera angle as Euler in tmp
                 Vector3 tmp = m_CameraTargetRot.eulerAngles;
                 //Debug.Log(tmp);
 
                 //Check if the x angle of the camera exceeds the $$anonymous$$ax or $$anonymous$$ and set it to max or $$anonymous$$ if it does
                 if (tmp.x > $$anonymous$$aximumX)
                 {
                     //Debug.Log("Greater than $$anonymous$$ax: " + tmp + " $$anonymous$$ax is: " + $$anonymous$$aximumX);
                     tmp.x = $$anonymous$$aximumX;
                     tmp.y = 90.0f;
                     tmp.z = 0.0f;
                     m_CameraTargetRot.eulerAngles = tmp;
                 }
                 if (tmp.x < $$anonymous$$inimumX)
                 {
                     //Debug.Log("Less than $$anonymous$$in: " + tmp + " $$anonymous$$in is: " + $$anonymous$$inimumX);
                     tmp.x = $$anonymous$$inimumX;
                     tmp.y = 90.0f;
                     tmp.z = 0.0f;
                     m_CameraTargetRot.eulerAngles = tmp;
                 }
 
                 camera.localRotation = m_CameraTargetRot;
                 
 
                 //Original
                 //m_CameraTargetRot = ClampRotationAroundXAxis(m_CameraTargetRot);
             }
 

avatar image
0

Answer by Gatling-Hawk-youtube · May 27, 2018 at 05:28 PM

I once removed the bone from the model and placed it within the first person camera... that worked

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Basic question about Unity functionality 0 Answers

camera scale 0 Answers

First Person Camera moves due to model 0 Answers

Adding components to prefab instead of player 0 Answers

Camera can't keep up with mouse when the FPS is low 0 Answers


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