Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Hydropulse17 · Jul 18, 2014 at 09:19 PM · camerajavascripttransformcamera rotateeulerangles

Return camera to original rotation values Logic

The title might not be very descriptive. I now how to to this, I just can't think of a logical way to implement it, if that makes any sense...Please read I have a camera parented to a truck(the player). If the player starts doing flips and stuff, upon landing the camera will be rotated in some weird manner. I have a script that was written mostly by my instructor, for the camera to make the view lag a bit when you turn the truck, as if the camera were a balloon attached to the truck by a string. By disabling that script and testing the game, I determined that the issue is a result of the script, but I would like very much to keep it. My idea was this

 var camRotX : float;
 var camRotZ : float;
 
 function Start(){ //defines original rotation values
 
     camRotX = transform.rotation.eulerAngles.x;
     camRotZ = transform.rotation.eulerAngles.z;
 }
 
 function Update (){ //sets current rotation values to original
     
     transform.rotation.eulerAngles.x = camRotX;
     transform.rotation.eulerAngles.z = camRotZ;
 }

This worked, except that it was maintaining the rotation of the camera constantly, so if you were to go up a slope, the camera would stare at the side of the mountain while the truck rotated with the grade. I thought maybe setting the rotation values only when the truck collides with the terrain would work, but I have no idea how to make my camera know when the truck hits the ground. I was thinking maybe some sort of ParentOnCollisionEnter might exist but I couldn't find anything in the scripting API.

I don't think it's necessary, but just in case, here is the whole script.

 var frameCounter : int = 0;
 var frameCycle_01 : int;
 var frameCycle_02 : int = 0;
 var rot_Y : float[] = new float[10];
 
 var camRotX : float;
 var camRotZ : float;
 
 
 
 function Start(){
     camRotX = transform.rotation.eulerAngles.x;
     camRotZ = transform.rotation.eulerAngles.z;
 }
 
 function Update () {
     
 
     frameCycle_01 = frameCounter%10;
     frameCycle_02 = (frameCounter + 1)%10;
     
     rot_Y[frameCycle_01] = TruckDriver.truckRotation.y;
 
     transform.rotation.eulerAngles.y = rot_Y[frameCycle_02];
     
     transform.rotation.eulerAngles.x = camRotX;
     transform.rotation.eulerAngles.z = camRotZ;
     
     frameCounter++;
 }
 

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
0

Answer by CScherer549 · Jul 20, 2014 at 08:06 PM

You're close with that first script, just think about what conditions you want those initial rotations to be applied. Probably not all the time right? If you're using a character controller, look into controller.isGrounded.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make camera 1 transform equal to camera 2 transform 1 Answer

Why is my Camera rotation tilted after parenting it to head? 1 Answer

NullReferenceException Error 1 Answer

LookAround Up&Down! 1 Answer

How to rotate my camera? 2 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