Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 TempestInATeacup · Jul 14, 2015 at 03:29 PM · c#rotationplayer movement

How to ensure that an object always rotates toward the camera?

I'm trying to make a program that lets its user rotate a model horizontally and vertically to look at different parts of it. I have horizontal rotation all set up, but vertical rotation is proving difficult. I want the user to, no matter how they've rotated the model horizontally, be able to tilt the model toward and away from them, with a 20 degree limit so they cant flip it all the way upside down.

Simple rotation on either the X or Z axis makes it so that when you rotate horizontally another 90 degrees, youll be seeing a sideways version of the model.

How do I set the object up to rotate in relation to the main camera while the user holds down the up and down arrow keys?

This is my current script:

 public float horizSpeed;
 public float vertiSpeed;
 public CharacterController cc;
 
 public GameObject artiSphere;

 void Start()
 {
     cc = GetComponent<CharacterController>();
 }

 void Update()
 {
     //horizontal rotation
     cc.transform.Rotate (new Vector3(0.0f, Input.GetAxis ("Horizontal")*horizSpeed*Time.deltaTime,0.0f));
 }
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 Alec-Slayden · Jul 14, 2015 at 04:32 PM 0
Share

do I understand correctly that you'd like it to rotate a local y axis, and a fixed x or z axis, so that it rotates around its own y axis for horizontal rotation, and around a fixed axis limiting -20 to +20 degrees of rotation? So one control allows the camera to look on 'top' or 'bottom' of the object and it will still rotate along its local axis, where the other control rotates the local axis?

Or is it specifically camera-relative at all times (projected axis)

avatar image TempestInATeacup · Jul 14, 2015 at 04:47 PM 0
Share

I don't want to rotate the camera if thats what you're asking, as I've tried that and it looked awkward and was hard to control. Projected axis sounds about right for what I'm trying to accomplish i think

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Flip over an object (smooth transition) 3 Answers

How to detect if player had switched direction of movement? 0 Answers

Will someone please help me??? 2 Answers

Need help rotating child of player based off of player movement. 1 Answer

How to make the player rotate to where an object is being thrown? 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