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 /
avatar image
0
Question by Eversmann · Mar 07, 2019 at 02:37 AM · cameraplayercharacteravatar

Player model not turning with the camera, always faces forward.

Probably a stupid question but, as you can see in the picture my player model is not turning itself to align towards where the camera is pointed (I am running towards the wall in the picture). Basically when I turn the camera the player turns with it, that all works fine. But the model always stays facing forward.

alt text

untitled.jpg (252.5 kB)
Comment
Add comment · Show 8
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 MasterChameleonGames · Mar 07, 2019 at 04:57 AM 0
Share

We need either the code or the hierarchy to understand.

avatar image Eversmann MasterChameleonGames · Mar 08, 2019 at 12:31 AM 0
Share

Hey, this is the script and the hierarchy. Basically there is an empty object that is a child of the player that the $$anonymous$$ainCamera follows. alt text

Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraFollow : $$anonymous$$onoBehaviour
 
 {
     public float Camera$$anonymous$$oveSpeed = 100.0f;
     public GameObject CameraFollowObj;
     Vector3 FollowPOS;
     public float clampAngle = 65.0f;
     public float inputSensitivity = 120.0f;
     private GameObject CameraObj;
     private GameObject PlayerObj;
     private float camDistanceXToPlayer;
     private float camDistanceYToPlayer;
     private float camDistanceZToPlayer;
     private float mouseX;
     private float mouseY;
     private float finalInputX;
     private float finalInputZ;
     private float smoothX;
     private float smoothY;
     private float rotY = 0.0f;
     private float rotX = 0.0f;
 
 
     // Use this for initialization
     void Start ()
 
     {
         Vector3 rot = transform.localRotation.eulerAngles;
         rotY = rot.y;
         rotX = rot.x;
         Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
         Cursor.visible = false;
     }
     
     // Update is called once per frame
     void Update ()
     {
         mouseX = Input.GetAxis ("$$anonymous$$ouse X");
         mouseY = Input.GetAxis ("$$anonymous$$ouse Y");
         finalInputX = mouseX;
         finalInputZ = mouseY;
 
         rotY += finalInputX * inputSensitivity * Time.deltaTime;
         rotX += finalInputZ * inputSensitivity * Time.deltaTime;
 
         rotX = $$anonymous$$athf.Clamp (rotX, -clampAngle, clampAngle);
 
         Quaternion localRotation = Quaternion.Euler (-rotX, rotY, 0.0f);
         transform.rotation = localRotation;  
     }
 
     void LateUpdate ()
 
     {
         CameraUpdater ();
     }
 
     void CameraUpdater()
 
     {
         // set the target object to follow
         Transform target = CameraFollowObj.transform;
 
         //move towards the game object that is the target
         float step = Camera$$anonymous$$oveSpeed * Time.deltaTime;
         transform.position = Vector3.$$anonymous$$oveTowards (transform.position, target.position, step);
     }
 }
 

avatar image MasterChameleonGames Eversmann · Mar 08, 2019 at 01:04 AM 0
Share

So you turn the camera using the mouse and the player turns when the camera turns? Do you have a script that turns the player object? It looks like you have a reference to PlayerObj but never use it.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MasterChameleonGames · Mar 09, 2019 at 09:35 PM

Figured it out, you're rotating the CameraFollow GameObject which is a child of Player, and the model is another child, so only CameraFollow is rotated.

Change transform.rotation = localRotation;
To transform.parent.rotation = localRotation;

That will rotate the parent which will rotate the models along with it.

Of course, this is assuming the code you gave is working as intended.

Comment
Add comment · Show 11 · 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 Eversmann · Mar 09, 2019 at 10:12 PM 0
Share

Doing that it gave me this error. And the camera stopped working.

 NullReferenceException: Object reference not set to an instance of an object
avatar image MasterChameleonGames Eversmann · Mar 09, 2019 at 10:52 PM 0
Share

Did you change anything else?

Also, try reverting back to what you had before and see if CameraFollow is rotating. You'll have to look at the inspector and see if the values change since it is an empty object.

avatar image MasterChameleonGames MasterChameleonGames · Mar 09, 2019 at 10:53 PM 0
Share

And this script is on the CameraFollow GameObject, the child of Player, right?

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.

Follow this Question

Answers Answers and Comments

202 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Using a Pre Rendered character as the player 0 Answers

How to make a camera that moves with the player? 1 Answer

Free Avatar Locations Anyone? 0 Answers

Character Controller Help. 1 Answer

Parenting a camera to different objects with input? 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