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 SirYo · May 14, 2018 at 06:00 PM · cameracamera rotatecamera movement

How to stop the player rotation after i stop the camera?

so i placed a google vr camera to my player and my camera has a script with

 public GameObject target;
 Vector3 rotateDirection;
 float y1;
 
 // Use this for initialization
 void Start () {

 }
 
 // Update is called once per frame
 void Update () {
     y1=transform.rotation.eulerAngles.y;
     rotateDirection = new Vector3(0, y1, 0);
     Quaternion rotatedri = Quaternion.Euler(0f, y1, 0f);
     target.transform.rotation = Quaternion.Slerp(target.transform.rotation, rotatedri, Time.deltaTime);
 }

i know the player will continue spinning while the camera y angle still has a value so my question is how to stop the player after i stop moving my camera ? or make the code better, im a beginner sorry #SorryForMyBadEnglandImNotEducation

Comment
Add comment · Show 6
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 iJuan · May 14, 2018 at 06:09 PM 0
Share

Wow, seems like your head is a mess.

Slerp will go from one point to other, over time. Your first point is the current, rotation, that's right. The second point should be your target rotation, which should depend on how much the player has rotated his head (Not sure how to do that, maybe an Input.GetAxis("Horizontal") ?)

So, you need to modify your "y1" only when the player rotates his head

Not sure if this will work, but try deleting y1=transform.rotation.eulerAngles.y, and replacing it with y1 = Input.GetAxis("Horizontal");

avatar image SirYo iJuan · May 14, 2018 at 06:35 PM 0
Share

"seems like your head is a mess" well thats right, im kinda living trash i tried your suggestion and its not working :/

avatar image iJuan iJuan · May 14, 2018 at 06:44 PM 0
Share

Try this one

 y1=InputTracking.GetLocalRotation (VRNode.CenterEye).eulerAngles.y;

I never worked with RV to be honest.

Also, that will rotate the camera only upwards and downwards

avatar image SirYo iJuan · May 14, 2018 at 07:52 PM 0
Share

not working neither

avatar image SirYo · May 15, 2018 at 06:51 AM 0
Share

i tried putting main camera as the parent of the player this will rotate the player too and this will fix the problem but when i rotate to look upward ( to look at the sky ) the player will rotate too he will go on horizontal position, please help

avatar image iJuan SirYo · May 15, 2018 at 04:30 PM 0
Share

So you want to rotate the camera or the player? I think you weren't very clear with your problem. What was exactly happening with the code you used before, and what did you expect to happen?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BGOKMEN14 · May 15, 2018 at 12:22 PM

Hello @SirYo!

I am not quite sure what you meant by stop the player rotation after camera stops, however, I believe I this is what you are looking for:

  public GameObject target;
  Vector3 rotateDirection;
  float y1;
 float y1OldValue;
  
  // Use this for initialization
  void Start () {
  }
  
  // Update is called once per frame
  void Update () {
      y1=transform.rotation.eulerAngles.y;
      rotateDirection = new Vector3(0, y1, 0);
      Quaternion rotatedri = Quaternion.Euler(0f, y1, 0f);
      target.transform.rotation = Quaternion.Slerp(target.transform.rotation, rotatedri, Time.deltaTime);
 if (y1 != y1OldValue) { //here the camera is still moving
                 y1OldValue = y1;
             } else  //here is when the camera stops
 {
                 //stop the player here
             }
  }

I hope this helps!

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

137 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

Related Questions

How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers

FPS Leaning movement! 0 Answers

Camera/can't turn on X 1 Answer

A smooth camera follow that allows for rotation functionality independent of the player. Maths? 1 Answer

Automatic Camera Rotation in the 3D Game Kit 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