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 aernbau · Nov 23, 2015 at 12:46 PM · rotation3rd person controller3rd person cameralocalrotationrelative rotation

transform.rotation and localRotation automatically reset after rotating.

I was trying to make a camera that's relative to the character, for a robot combat game like Zone of the Enders, Project Nimbus, Strike Suit Zero/Infinity, etc. and I can't get rotation/localRotation to work properly.

     float hor = Input.GetAxis("Mouse X") * smooth;
     float ver = Input.GetAxis("Mouse Y") * smooth;
     
     /*
     if(!target.IsGrounded())
         target.transform.Rotate(-ver, hor, 0);
     else
         target.transform.Rotate(0, hor, 0);
     */
     /*
     if(!target.IsGrounded())
         target.transform.localRotation = Quaternion.Euler(-ver, hor, 0);
     else
         target.transform.localRotation = Quaternion.Euler(0, hor, 0);
     */

The target is a GameObject. The grounding is irrelevant. If I use Rotate, it rotates 'alright', but not how I want to. If I use rotation/localRotation, it rotates, but only for 1 frame, then returns to the default position. transform.eulerAngles does the same thing. Even if I make an empty game object that is supposed to just exist and spin something by its local rotation, it will not.

I am pretty new to Unity, not new to coding so it doesn't make sense to me how this doesn't work. Please help.

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
1
Best Answer

Answer by aernbau · Nov 23, 2015 at 03:10 PM

Don't you love it how you find the answer only after trying to ask someone else?

I've made 2 extra floats to add on the mouse movement. Pretty sure I'll find out I've done something wrong on some other part, but for now...

     float hor_mouse = Input.GetAxis("Mouse X");
     float ver_mouse = Input.GetAxis("Mouse Y");
     hor += hor_mouse;
     ver += ver_mouse;    
     //testtarget.transform.Rotate(-ver, 2, 0);
     testtarget.transform.localRotation = Quaternion.Euler(-ver,hor,0);

Yay.

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 tarunchand28021998 · Jan 15, 2018 at 03:06 PM 0
Share

I have a similar problem and I kind of know what is happening but don't know what to do about it. can you help me out with this one?

 //for rotation(this code is inside the update function):
         newposition = rb.position;
         Vector3 velocity = newposition - lastposition;
         lastposition = rb.position;
 
         Vector3 direction = velocity.normalized;
         Quaternion lookrotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
         rb.rotation = lookrotation;

I want the object to face the direction of its movement and it does while it is moving but i want it to stay after it has stopped moving and not return to its default y=0 rotation. Please help.

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

How to make the character move and rotate where the camera is facing (3rd person) 0 Answers

How to get JUST the y rotation of an object? 3 Answers

Using gamepad triggers to control 3rd person camera 2 Answers

How to move player in direction where the camera is aiming ? 1 Answer

child lookat another child 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